using System;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;
using C1.Win.C1Input;
using C1.Win.C1Preview;
using C1.C1Report;
using C1.Win.C1TrueDBGrid;
using PCSComMaterials.Plan.DS;
using PCSComProduction.DCP.BO;
using PCSComProduction.WorkOrder.BO;
using PCSComProduction.WorkOrder.DS;
using PCSComUtils.Common;
using PCSComUtils.Common.BO;
using PCSComUtils.MasterSetup.DS;
using PCSComUtils.PCSExc;
using PCSUtils.Framework.ReportFrame;
using PCSUtils.Log;
using PCSUtils.Utils;
using PCSComUtils.DataContext;
using System.Collections.Generic;
using C1PrintPreviewDialog = PCSUtils.Framework.ReportFrame.C1PrintPreviewDialog;

namespace PCSProduction.WorkOrder
{
    /// <summary>
    /// This class uses to establish and maintain Work Order.
    /// </summary>
    public class WorkOrder : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Label lblMasLoc;
        private System.Windows.Forms.Label lblCCN;
        private System.Windows.Forms.Label lblTransDate;
        private System.Windows.Forms.CheckBox chkManufacture;
        private System.Windows.Forms.CheckBox chkFinance;
        private System.Windows.Forms.TextBox txtDescription;
        private System.Windows.Forms.Label lblDescription;
        private System.Windows.Forms.TextBox txtWONo;
        private System.Windows.Forms.Label lblWO_No;
        private System.Windows.Forms.Button btnEdit;
        private System.Windows.Forms.Button btnClose;
        private System.Windows.Forms.Button btnHelp;
        private System.Windows.Forms.Button btnDelete;
        private System.Windows.Forms.Button btnSave;
        private System.Windows.Forms.Button btnAdd;
        private System.Windows.Forms.Button btnPrint;
        private System.Windows.Forms.Button btnRouting;
        private System.Windows.Forms.Button btnBOM;
        private System.Windows.Forms.Button btnCost;
        private System.Windows.Forms.Button btnSearchWO;
        private C1.Win.C1TrueDBGrid.C1TrueDBGrid dgrdData;
        private System.Windows.Forms.TextBox txtMasterLocation;
        private System.Windows.Forms.Button btnSearchMasLoc;
        private C1.Win.C1Input.C1DateEdit dtmTransDate;
        private C1.Win.C1List.C1Combo cboCCN;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        private PCSComProduction.WorkOrder.BO.WorkOrderBO boWorkOrder = new WorkOrderBO();
        public const string THIS = "PCSProduction.WorkOrder.WorkOrder";

        private const string UNRELEASE = "UnRelease";
        private const string SALE_ORDER_CODE = "SaleOrderCode";
        private const string UM = "UM";
        private const string AGC_CODE = "AGCCode";
        private const string SALE_ORDER_FOR_WOLINE_VIEWNAME = "v_SaleOrderForWOLine";

        private const string STATUS_STRING = "StatusString";
        private const int UM_CODE = 0;
        private const int COST_METHOD = 1;
        private const int AGC_COD = 2;
        private const int EST_CODE = 3;
        private string ReportDefinitionFolder = string.Empty;
        private const string ReportFileName = "WorkOrderReport.xml";
        private const string ReportWorkOrderLine = "WorkOrderLine.xml";

        private DataTable dtbGridLayOut;
        private PRO_WorkOrderMaster voWorkOrderMaster = new PRO_WorkOrderMaster();
        private DataSet dstGridData;
        private MST_MasterLocationVO voMasLoc = new MST_MasterLocationVO();
        private EnumAction mFormMode = EnumAction.Default;
        private ArrayList ArlWOLineID = new ArrayList();
        private C1.Win.C1Input.C1DateEdit dtmDate;
        private bool blnHasError = false;
        string strLastValidPro = string.Empty;

        public EnumAction FormMode
        {
            get { return mFormMode; }
            set { mFormMode = value; }
        }

        private WOFormState mWOFormState = WOFormState.Normal;
        private MTR_CPOVO voCPO;
        private System.Windows.Forms.TextBox txtProductionLine;
        private System.Windows.Forms.Label lblProductionLine;
        private System.Windows.Forms.Button btnProductionLine;
        private System.Windows.Forms.Label lblWorkOrderReport;
        private System.Windows.Forms.TextBox txtDCPCycle;
        private System.Windows.Forms.Label lblDCPCycle;
        private System.Windows.Forms.Button btnDCPCycle;
        private System.Windows.Forms.TextBox txtDCPDescription;
        private System.Windows.Forms.TextBox txtFGoodsCode;
        private System.Windows.Forms.TextBox txtSaleOrderCode;
        private System.Windows.Forms.Label lblFGoodsCode;
        private System.Windows.Forms.Button btnFGoodsCode;
        private System.Windows.Forms.Label lblSaleOrderCode;
        private System.Windows.Forms.Button btnSaleOrderCode;
        private System.Windows.Forms.Button btnPrintWOLine;
        private System.Windows.Forms.Button btnEditBOM;
        private Button btnSuaBSX;
        private DataView dtwCPOs;
        public WorkOrder()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
        }
        public WorkOrder(int pintWOMasterID, int pintCCNID, int pintMasLocID, string pstrMasLoc)
        {
            const string METHOD_NAME = THIS + ".WorkOrder()";
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            voWorkOrderMaster.WorkOrderMasterID = pintWOMasterID;
            voMasLoc.MasterLocationID = pintMasLocID;
            txtMasterLocation.Text = pstrMasLoc;
            UtilsBO boUtils = new UtilsBO();
            DataSet dstCCN = boUtils.ListCCN();
            cboCCN.DataSource = dstCCN.Tables[MST_CCNTable.TABLE_NAME];
            cboCCN.DisplayMember = MST_CCNTable.CODE_FLD;
            cboCCN.ValueMember = MST_CCNTable.CCNID_FLD;
            FormControlComponents.PutDataIntoC1ComboBox(cboCCN, dstCCN.Tables[MST_CCNTable.TABLE_NAME], MST_CCNTable.CODE_FLD, MST_CCNTable.CCNID_FLD, MST_CCNTable.TABLE_NAME);
            cboCCN.SelectedValue = pintCCNID;
        }

        public WorkOrder(DataView pdtwCPOs, int pintWOMasterID, object pobjCPO)
        {
            InitializeComponent();
            mWOFormState = WOFormState.CPOExistWO;
            voCPO = (MTR_CPOVO)pobjCPO;
            if (pdtwCPOs != null)
            {
                dtwCPOs = pdtwCPOs;
            }
            else pdtwCPOs = null;
            voWorkOrderMaster.WorkOrderMasterID = pintWOMasterID;
        }

        /// <summary>
        /// Convert CPO to existing WO
        /// </summary>
        private void FormLoadForExistWOForCPO()
        {
            if (dtwCPOs == null || voWorkOrderMaster.WorkOrderMasterID == 0)
                return;
            cboCCN.SelectedValue = voCPO.CCNID;
            txtMasterLocation.Text = boWorkOrder.GetMasterLocByID(voCPO.MasterLocationID).Code;
            voMasLoc.MasterLocationID = voCPO.MasterLocationID;

            voWorkOrderMaster = boWorkOrder.GetWorkOrderDetail(voWorkOrderMaster.WorkOrderMasterID);
            txtDescription.Text = voWorkOrderMaster.Description;
            txtWONo.Text = voWorkOrderMaster.WorkOrderNo;

            if (voWorkOrderMaster.ProductionLineID > 0)
            {
                DataRowView drvProLine = FormControlComponents.OpenSearchForm(PRO_ProductionLineTable.TABLE_NAME, PRO_ProductionLineTable.PRODUCTIONLINEID_FLD, voWorkOrderMaster.ProductionLineID.ToString(), null, false);
                if (drvProLine != null)
                {
                    txtProductionLine.Text = drvProLine[PRO_ProductionLineTable.CODE_FLD].ToString();
                    txtProductionLine.Tag = drvProLine[PRO_ProductionLineTable.PRODUCTIONLINEID_FLD];
                }
            }
            if (voWorkOrderMaster.DCOptionMasterID > 0)
            {
                DataRowView drvProLine = FormControlComponents.OpenSearchForm(PRO_DCOptionMasterTable.TABLE_NAME, PRO_DCOptionMasterTable.DCOPTIONMASTERID_FLD, voWorkOrderMaster.DCOptionMasterID.ToString(), null, false);
                if (drvProLine != null)
                {
                    txtDCPCycle.Text = drvProLine[PRO_DCOptionMasterTable.CYCLE_FLD].ToString();
                    txtDCPCycle.Tag = drvProLine[PRO_DCOptionMasterTable.DCOPTIONMASTERID_FLD];
                    txtDCPDescription.Text = drvProLine[PRO_DCOptionMasterTable.DESCRIPTION_FLD].ToString();
                }
            }
            dtmTransDate.Value = voWorkOrderMaster.TransDate;
            chkFinance.Checked = false;
            chkManufacture.Checked = false;
            dstGridData = boWorkOrder.GetWODetailByMaster(voWorkOrderMaster.WorkOrderMasterID);
            dstGridData.EnforceConstraints = false;
            for (int i = 0; i < dtwCPOs.Count; i++)
            {
                DataRow drowWODetail = dstGridData.Tables[0].NewRow();
                drowWODetail[PRO_WorkOrderDetailTable.LINE_FLD] = int.Parse(dstGridData.Tables[0].Rows[dstGridData.Tables[0].Rows.Count - 1][PRO_WorkOrderDetailTable.LINE_FLD].ToString()) + 1;
                drowWODetail[ITM_ProductTable.PRODUCTID_FLD] = dtwCPOs[i][ITM_ProductTable.PRODUCTID_FLD];
                drowWODetail[ITM_ProductTable.STOCKUMID_FLD] = dtwCPOs[i][ITM_ProductTable.STOCKUMID_FLD];
                drowWODetail[ITM_ProductTable.CODE_FLD] = dtwCPOs[i][ITM_ProductTable.TABLE_NAME + ITM_ProductTable.CODE_FLD];
                drowWODetail[ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD] = dtwCPOs[i][ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD];
                drowWODetail[ITM_ProductTable.REVISION_FLD] = dtwCPOs[i][ITM_ProductTable.TABLE_NAME + ITM_ProductTable.REVISION_FLD];
                drowWODetail[UM] = dtwCPOs[i][MST_UnitOfMeasureTable.TABLE_NAME + MST_UnitOfMeasureTable.CODE_FLD];
                drowWODetail[PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD] = dtwCPOs[i][MTR_CPOTable.QUANTITY_FLD];
                drowWODetail[PRO_WorkOrderDetailTable.STARTDATE_FLD] = dtwCPOs[i][MTR_CPOTable.STARTDATE_FLD];
                drowWODetail[PRO_WorkOrderDetailTable.DUEDATE_FLD] = dtwCPOs[i][MTR_CPOTable.DUEDATE_FLD];
                drowWODetail[STATUS_STRING] = UNRELEASE;
                drowWODetail[PRO_WorkOrderDetailTable.STATUS_FLD] = WOLineStatus.Unreleased;
                drowWODetail[PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD] = DBNull.Value;
                dstGridData.Tables[0].Rows.Add(drowWODetail);
            }
            dgrdData.DataSource = dstGridData.Tables[0];
            for (int i = 0; i < dgrdData.RowCount; i++)
            {
                string strProductInfor;
                char chrSeparator = ';';
                strProductInfor = boWorkOrder.GetProductInforByID(int.Parse(dgrdData[i, PRO_WorkOrderDetailTable.PRODUCTID_FLD].ToString()));
                dgrdData[i, UM] = strProductInfor.Split(chrSeparator)[UM_CODE];
                dgrdData[i, ITM_ProductTable.COSTMETHOD_FLD] = strProductInfor.Split(chrSeparator)[COST_METHOD];
                dgrdData[i, AGC_CODE] = strProductInfor.Split(chrSeparator)[AGC_COD];
                dgrdData[i, PRO_WorkOrderDetailTable.STARTDATE_FLD] = new UtilsBO().GetDBDate();
                if (strProductInfor.Split(chrSeparator)[EST_CODE] != string.Empty)
                {
                    dgrdData[i, PRO_WorkOrderDetailTable.ESTCST_FLD] = strProductInfor.Split(chrSeparator)[EST_CODE];
                }
                else
                {
                    dgrdData[i, PRO_WorkOrderDetailTable.ESTCST_FLD] = DBNull.Value;
                }
                if (dgrdData[i, PRO_WorkOrderDetailTable.AGC_FLD].ToString() == string.Empty)
                {
                    dgrdData[i, PRO_WorkOrderDetailTable.AGC_FLD] = DBNull.Value;
                }
                if (dgrdData[i, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString() == string.Empty)
                {
                    dgrdData[i, STATUS_STRING] = UNRELEASE;
                    dgrdData[i, PRO_WorkOrderDetailTable.STATUS_FLD] = (int)WOLineStatus.Unreleased;
                }
            }
            //restore the layout of grid
            FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayOut);
            ConfigGrid(false);

            //enable and disbale button
            btnAdd.Enabled = false;
            if (CheckWOLines(WOLineStatus.MfgClose))
            {
                chkManufacture.Checked = true;
            }
            else
            {
                if (CheckWOLines(WOLineStatus.FinClose))
                {
                    chkFinance.Checked = true;
                }
            }
            mFormMode = EnumAction.Edit;
            SwitchFormMode();
        }

        /// <summary>
        /// - Fill data into item code, item description, item revision, stock unit of measure 
        /// - Fill data into start/due date time based on current server date time
        /// - Fill data into AGC, cost method, estimated cost based on product item setup
        /// </summary>
        private void FillItemData(DataRow pdrowData)
        {
            int i = dgrdData.Row;

            int intRountCount = dgrdData.RowCount;
            for (int row = 0; row < intRountCount; row++)
            {
                if (dgrdData[row, ITM_ProductTable.CODE_FLD].ToString() == pdrowData[ITM_ProductTable.PRODUCTID_FLD].ToString())
                {
                    PCSMessageBox.Show(ErrorCode.DUPLICATE_KEY, MessageBoxIcon.Error);
                    dgrdData.Row = row;
                    dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.CODE_FLD]);
                    dgrdData.Focus();
                    return;
                }
            }
            dgrdData.EditActive = true;
            if (dgrdData.AddNewMode != AddNewModeEnum.NoAddNew)
                dgrdData[i, PRO_WorkOrderDetailTable.LINE_FLD] = i + 1;
            dgrdData[i, ITM_ProductTable.CODE_FLD] = pdrowData[ITM_ProductTable.CODE_FLD].ToString();
            dgrdData[i, ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD] = pdrowData[ITM_ProductTable.DESCRIPTION_FLD].ToString();
            dgrdData[i, ITM_ProductTable.REVISION_FLD] = pdrowData[ITM_ProductTable.REVISION_FLD].ToString();

            //HACK: added by Tuan TQ. 23 May, 2006. Set value to Category column
            if (pdrowData[ITM_ProductTable.CATEGORYID_FLD] != null && pdrowData[ITM_ProductTable.CATEGORYID_FLD] != DBNull.Value)
            {
                string strCategory = FormControlComponents.OpenSearchForm(ITM_CategoryTable.TABLE_NAME,
                    ITM_CategoryTable.CATEGORYID_FLD, pdrowData[ITM_ProductTable.CATEGORYID_FLD].ToString(),
                    null, false)[ITM_CategoryTable.CODE_FLD].ToString();
                dgrdData[i, ITM_CategoryTable.TABLE_NAME + ITM_CategoryTable.CODE_FLD] = strCategory;
            }
            //End hack

            dgrdData[i, PRO_WorkOrderDetailTable.PRODUCTID_FLD] = pdrowData[ITM_ProductTable.PRODUCTID_FLD].ToString();
            dgrdData[i, PRO_WorkOrderDetailTable.STOCKUMID_FLD] = pdrowData[ITM_ProductTable.STOCKUMID_FLD].ToString();
            dgrdData[i, PRO_WorkOrderDetailTable.GROUP1_FLD] = pdrowData[ITM_ProductTable.GROUP1_FLD].ToString();
            dgrdData[i, PRO_WorkOrderDetailTable.GROUP2_FLD] = pdrowData[ITM_ProductTable.GROUP2_FLD].ToString();
            dgrdData[i, PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD] = pdrowData[ITM_ProductTable.GROUPQUANTITY_FLD];
            dgrdData[i, PRO_WorkOrderDetailTable.AGC_FLD] = pdrowData[ITM_ProductTable.AGCID_FLD].ToString();
            string strProductInfor;
            char chrSeparator = ';';
            strProductInfor = boWorkOrder.GetProductInforByID(int.Parse(pdrowData[PRO_WorkOrderDetailTable.PRODUCTID_FLD].ToString()));
            dgrdData[i, UM] = strProductInfor.Split(chrSeparator)[UM_CODE];
            dgrdData[i, ITM_ProductTable.COSTMETHOD_FLD] = strProductInfor.Split(chrSeparator)[COST_METHOD];
            dgrdData[i, AGC_CODE] = strProductInfor.Split(chrSeparator)[AGC_COD];
            dgrdData[i, PRO_WorkOrderDetailTable.STARTDATE_FLD] = new UtilsBO().GetDBDate();
            if (strProductInfor.Split(chrSeparator)[EST_CODE] != string.Empty)
                dgrdData[i, PRO_WorkOrderDetailTable.ESTCST_FLD] = strProductInfor.Split(chrSeparator)[EST_CODE];
            else
                dgrdData[i, PRO_WorkOrderDetailTable.ESTCST_FLD] = DBNull.Value;
            if (dgrdData[i, PRO_WorkOrderDetailTable.AGC_FLD].ToString() == string.Empty)
                dgrdData[i, PRO_WorkOrderDetailTable.AGC_FLD] = DBNull.Value;
            if (dgrdData[i, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString() == string.Empty)
            {
                dgrdData[i, STATUS_STRING] = UNRELEASE;
                dgrdData[i, PRO_WorkOrderDetailTable.STATUS_FLD] = (int)WOLineStatus.Unreleased;
            }
            dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.CODE_FLD]);
            dgrdData.Focus();
        }

        private void FillProductionLine(DataRow pdrowData)
        {
            int i = dgrdData.Row;

            dgrdData.EditActive = true;
            if (dgrdData.AddNewMode != AddNewModeEnum.NoAddNew)
                dgrdData[i, PRO_WorkOrderDetailTable.LINE_FLD] = i + 1;
            dgrdData[i, PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD] = pdrowData[PRO_ProductionLineTable.CODE_FLD].ToString();
            dgrdData[i, PRO_ProductionLineTable.PRODUCTIONLINEID_FLD] = pdrowData[PRO_ProductionLineTable.PRODUCTIONLINEID_FLD].ToString();
            dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD]);
            dgrdData.Focus();
        }

        /// <summary>
        /// check all work order line in grid, 
        /// if all work order line have status is unrelease
        /// 	allow delete
        /// else
        /// {
        /// display error message that user cannot delete because all line is not unrelease
        /// return;
        /// }
        /// </summary>
        private bool CheckWOLines(WOLineStatus pStatusToCheck)
        {
            int intCountStatus = 0, intCountLineDetail = 0;
            for (int i = 0; i < dgrdData.RowCount; i++)
            {
                if (dgrdData[i, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString() != string.Empty)
                {
                    intCountLineDetail++;
                    if (pStatusToCheck == WOLineStatus.FinClose)
                    {
                        if (int.Parse(dgrdData[i, PRO_WorkOrderDetailTable.STATUS_FLD].ToString()) == (int)pStatusToCheck)
                            intCountStatus++;
                    }
                    if (pStatusToCheck == WOLineStatus.MfgClose)
                    {
                        if (int.Parse(dgrdData[i, PRO_WorkOrderDetailTable.STATUS_FLD].ToString()) == (int)pStatusToCheck
                            || int.Parse(dgrdData[i, PRO_WorkOrderDetailTable.STATUS_FLD].ToString()) == (int)WOLineStatus.FinClose)
                            intCountStatus++;
                    }
                    if (pStatusToCheck == WOLineStatus.Unreleased)
                    {
                        if (int.Parse(dgrdData[i, PRO_WorkOrderDetailTable.STATUS_FLD].ToString()) == (int)WOLineStatus.Unreleased)
                            intCountStatus++;
                    }
                }
            }
            if (intCountStatus == intCountLineDetail)
                return true;
            else
                return false;
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }


        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WorkOrder));
            C1.Win.C1TrueDBGrid.Style style22 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style23 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style24 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style25 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style26 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style27 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style28 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style29 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style30 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style31 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style32 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style33 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style34 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1List.Style style35 = new C1.Win.C1List.Style();
            C1.Win.C1List.Style style36 = new C1.Win.C1List.Style();
            C1.Win.C1List.Style style37 = new C1.Win.C1List.Style();
            C1.Win.C1List.Style style38 = new C1.Win.C1List.Style();
            C1.Win.C1List.Style style39 = new C1.Win.C1List.Style();
            C1.Win.C1List.Style style40 = new C1.Win.C1List.Style();
            C1.Win.C1List.Style style41 = new C1.Win.C1List.Style();
            C1.Win.C1List.Style style42 = new C1.Win.C1List.Style();
            this.dgrdData = new C1.Win.C1TrueDBGrid.C1TrueDBGrid();
            this.btnSearchWO = new System.Windows.Forms.Button();
            this.chkManufacture = new System.Windows.Forms.CheckBox();
            this.chkFinance = new System.Windows.Forms.CheckBox();
            this.txtDescription = new System.Windows.Forms.TextBox();
            this.lblDescription = new System.Windows.Forms.Label();
            this.txtWONo = new System.Windows.Forms.TextBox();
            this.lblWO_No = new System.Windows.Forms.Label();
            this.lblMasLoc = new System.Windows.Forms.Label();
            this.lblCCN = new System.Windows.Forms.Label();
            this.btnEdit = new System.Windows.Forms.Button();
            this.btnClose = new System.Windows.Forms.Button();
            this.btnHelp = new System.Windows.Forms.Button();
            this.btnDelete = new System.Windows.Forms.Button();
            this.btnSave = new System.Windows.Forms.Button();
            this.btnAdd = new System.Windows.Forms.Button();
            this.btnPrint = new System.Windows.Forms.Button();
            this.lblTransDate = new System.Windows.Forms.Label();
            this.btnRouting = new System.Windows.Forms.Button();
            this.btnBOM = new System.Windows.Forms.Button();
            this.btnCost = new System.Windows.Forms.Button();
            this.txtMasterLocation = new System.Windows.Forms.TextBox();
            this.btnSearchMasLoc = new System.Windows.Forms.Button();
            this.dtmTransDate = new C1.Win.C1Input.C1DateEdit();
            this.cboCCN = new C1.Win.C1List.C1Combo();
            this.dtmDate = new C1.Win.C1Input.C1DateEdit();
            this.txtProductionLine = new System.Windows.Forms.TextBox();
            this.lblProductionLine = new System.Windows.Forms.Label();
            this.btnProductionLine = new System.Windows.Forms.Button();
            this.lblWorkOrderReport = new System.Windows.Forms.Label();
            this.txtDCPCycle = new System.Windows.Forms.TextBox();
            this.lblDCPCycle = new System.Windows.Forms.Label();
            this.btnDCPCycle = new System.Windows.Forms.Button();
            this.txtDCPDescription = new System.Windows.Forms.TextBox();
            this.txtFGoodsCode = new System.Windows.Forms.TextBox();
            this.txtSaleOrderCode = new System.Windows.Forms.TextBox();
            this.lblFGoodsCode = new System.Windows.Forms.Label();
            this.btnFGoodsCode = new System.Windows.Forms.Button();
            this.lblSaleOrderCode = new System.Windows.Forms.Label();
            this.btnSaleOrderCode = new System.Windows.Forms.Button();
            this.btnPrintWOLine = new System.Windows.Forms.Button();
            this.btnEditBOM = new System.Windows.Forms.Button();
            this.btnSuaBSX = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.dgrdData)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dtmTransDate)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.cboCCN)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dtmDate)).BeginInit();
            this.SuspendLayout();
            // 
            // dgrdData
            // 
            this.dgrdData.AccessibleDescription = null;
            this.dgrdData.AccessibleName = null;
            resources.ApplyResources(this.dgrdData, "dgrdData");
            this.dgrdData.BackgroundImage = null;
            this.dgrdData.CaptionStyle = style22;
            this.dgrdData.ChildGrid = null;
            this.dgrdData.EditorStyle = style23;
            this.dgrdData.EvenRowStyle = style24;
            this.dgrdData.FilterBarStyle = style25;
            this.dgrdData.FooterStyle = style26;
            this.dgrdData.GroupStyle = style27;
            this.dgrdData.HeadingStyle = style28;
            this.dgrdData.HighLightRowStyle = style29;
            this.dgrdData.Images.Add(((System.Drawing.Image)(resources.GetObject("dgrdData.Images"))));
            this.dgrdData.InactiveStyle = style30;
            this.dgrdData.MarqueeStyle = C1.Win.C1TrueDBGrid.MarqueeEnum.DottedCellBorder;
            this.dgrdData.Name = "dgrdData";
            this.dgrdData.OddRowStyle = style31;
            this.dgrdData.PictureAddnewRow = null;
            this.dgrdData.PictureCurrentRow = null;
            this.dgrdData.PictureFilterBar = null;
            this.dgrdData.PictureFooterRow = null;
            this.dgrdData.PictureHeaderRow = null;
            this.dgrdData.PictureModifiedRow = null;
            this.dgrdData.PictureStandardRow = null;
            this.dgrdData.PreviewInfo.AllowSizing = ((bool)(resources.GetObject("dgrdData.PreviewInfo.AllowSizing")));
            this.dgrdData.PreviewInfo.Caption = resources.GetString("dgrdData.PreviewInfo.Caption");
            this.dgrdData.PreviewInfo.Location = ((System.Drawing.Point)(resources.GetObject("dgrdData.PreviewInfo.Location")));
            this.dgrdData.PreviewInfo.Size = ((System.Drawing.Size)(resources.GetObject("dgrdData.PreviewInfo.Size")));
            this.dgrdData.PreviewInfo.ToolBars = ((bool)(resources.GetObject("dgrdData.PreviewInfo.ToolBars")));
            this.dgrdData.PreviewInfo.UIStrings.Content = ((string[])(resources.GetObject("dgrdData.PreviewInfo.UIStrings.Content")));
            this.dgrdData.PreviewInfo.ZoomFactor = ((double)(resources.GetObject("dgrdData.PreviewInfo.ZoomFactor")));
            this.dgrdData.PrintInfo.MaxRowHeight = ((int)(resources.GetObject("dgrdData.PrintInfo.MaxRowHeight")));
            this.dgrdData.PrintInfo.OwnerDrawPageFooter = ((bool)(resources.GetObject("dgrdData.PrintInfo.OwnerDrawPageFooter")));
            this.dgrdData.PrintInfo.OwnerDrawPageHeader = ((bool)(resources.GetObject("dgrdData.PrintInfo.OwnerDrawPageHeader")));
            this.dgrdData.PrintInfo.PageFooter = resources.GetString("dgrdData.PrintInfo.PageFooter");
            this.dgrdData.PrintInfo.PageFooterHeight = ((int)(resources.GetObject("dgrdData.PrintInfo.PageFooterHeight")));
            this.dgrdData.PrintInfo.PageHeader = resources.GetString("dgrdData.PrintInfo.PageHeader");
            this.dgrdData.PrintInfo.PageHeaderHeight = ((int)(resources.GetObject("dgrdData.PrintInfo.PageHeaderHeight")));
            this.dgrdData.PrintInfo.PageSettings = ((System.Drawing.Printing.PageSettings)(resources.GetObject("dgrdData.PrintInfo.PageSettings")));
            this.dgrdData.PrintInfo.PrintHorizontalSplits = ((bool)(resources.GetObject("dgrdData.PrintInfo.PrintHorizontalSplits")));
            this.dgrdData.PrintInfo.ProgressCaption = resources.GetString("dgrdData.PrintInfo.ProgressCaption");
            this.dgrdData.PrintInfo.RepeatColumnFooters = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatColumnFooters")));
            this.dgrdData.PrintInfo.RepeatColumnHeaders = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatColumnHeaders")));
            this.dgrdData.PrintInfo.RepeatGridHeader = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatGridHeader")));
            this.dgrdData.PrintInfo.RepeatSplitHeaders = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatSplitHeaders")));
            this.dgrdData.PrintInfo.ShowOptionsDialog = ((bool)(resources.GetObject("dgrdData.PrintInfo.ShowOptionsDialog")));
            this.dgrdData.PrintInfo.ShowProgressForm = ((bool)(resources.GetObject("dgrdData.PrintInfo.ShowProgressForm")));
            this.dgrdData.PrintInfo.ShowSelection = ((bool)(resources.GetObject("dgrdData.PrintInfo.ShowSelection")));
            this.dgrdData.PrintInfo.UseGridColors = ((bool)(resources.GetObject("dgrdData.PrintInfo.UseGridColors")));
            this.dgrdData.RecordSelectorStyle = style32;
            this.dgrdData.RowDivider.Color = ((System.Drawing.Color)(resources.GetObject("resource.Color")));
            this.dgrdData.RowDivider.Style = ((C1.Win.C1TrueDBGrid.LineStyleEnum)(resources.GetObject("resource.Style")));
            this.dgrdData.SelectedStyle = style33;
            this.dgrdData.Style = style34;
            this.dgrdData.BeforeColEdit += new C1.Win.C1TrueDBGrid.BeforeColEditEventHandler(this.dgrdData_BeforeColEdit);
            this.dgrdData.ButtonClick += new C1.Win.C1TrueDBGrid.ColEventHandler(this.dgrdData_ButtonClick);
            this.dgrdData.BeforeColUpdate += new C1.Win.C1TrueDBGrid.BeforeColUpdateEventHandler(this.dgrdData_BeforeColUpdate);
            this.dgrdData.BeforeDelete += new C1.Win.C1TrueDBGrid.CancelEventHandler(this.dgrdData_BeforeDelete);
            this.dgrdData.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dgrdData_KeyDown);
            this.dgrdData.Enter += new System.EventHandler(this.dgrdData_Enter);
            this.dgrdData.AfterDelete += new System.EventHandler(this.dgrdData_AfterDelete);
            this.dgrdData.AfterColUpdate += new C1.Win.C1TrueDBGrid.ColEventHandler(this.dgrdData_AfterColUpdate);
            this.dgrdData.RowColChange += new C1.Win.C1TrueDBGrid.RowColChangeEventHandler(this.dgrdData_RowColChange);
            // 
            // btnSearchWO
            // 
            this.btnSearchWO.AccessibleDescription = null;
            this.btnSearchWO.AccessibleName = null;
            resources.ApplyResources(this.btnSearchWO, "btnSearchWO");
            this.btnSearchWO.BackgroundImage = null;
            this.btnSearchWO.Font = null;
            this.btnSearchWO.Name = "btnSearchWO";
            this.btnSearchWO.Click += new System.EventHandler(this.btnSearchWO_Click);
            // 
            // chkManufacture
            // 
            this.chkManufacture.AccessibleDescription = null;
            this.chkManufacture.AccessibleName = null;
            resources.ApplyResources(this.chkManufacture, "chkManufacture");
            this.chkManufacture.BackgroundImage = null;
            this.chkManufacture.Font = null;
            this.chkManufacture.Name = "chkManufacture";
            // 
            // chkFinance
            // 
            this.chkFinance.AccessibleDescription = null;
            this.chkFinance.AccessibleName = null;
            resources.ApplyResources(this.chkFinance, "chkFinance");
            this.chkFinance.BackgroundImage = null;
            this.chkFinance.Font = null;
            this.chkFinance.Name = "chkFinance";
            // 
            // txtDescription
            // 
            this.txtDescription.AccessibleDescription = null;
            this.txtDescription.AccessibleName = null;
            resources.ApplyResources(this.txtDescription, "txtDescription");
            this.txtDescription.BackgroundImage = null;
            this.txtDescription.Font = null;
            this.txtDescription.Name = "txtDescription";
            this.txtDescription.Leave += new System.EventHandler(this.txtDescription_Leave);
            this.txtDescription.Enter += new System.EventHandler(this.OnEnterControl);
            // 
            // lblDescription
            // 
            this.lblDescription.AccessibleDescription = null;
            this.lblDescription.AccessibleName = null;
            resources.ApplyResources(this.lblDescription, "lblDescription");
            this.lblDescription.Font = null;
            this.lblDescription.Name = "lblDescription";
            // 
            // txtWONo
            // 
            this.txtWONo.AccessibleDescription = null;
            this.txtWONo.AccessibleName = null;
            resources.ApplyResources(this.txtWONo, "txtWONo");
            this.txtWONo.BackgroundImage = null;
            this.txtWONo.Font = null;
            this.txtWONo.Name = "txtWONo";
            this.txtWONo.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtWONo_KeyDown);
            this.txtWONo.Leave += new System.EventHandler(this.txtWONo_Leave);
            this.txtWONo.Enter += new System.EventHandler(this.OnEnterControl);
            this.txtWONo.Validating += new System.ComponentModel.CancelEventHandler(this.txtWONo_Validating);
            // 
            // lblWO_No
            // 
            this.lblWO_No.AccessibleDescription = null;
            this.lblWO_No.AccessibleName = null;
            resources.ApplyResources(this.lblWO_No, "lblWO_No");
            this.lblWO_No.Font = null;
            this.lblWO_No.ForeColor = System.Drawing.Color.Maroon;
            this.lblWO_No.Name = "lblWO_No";
            // 
            // lblMasLoc
            // 
            this.lblMasLoc.AccessibleDescription = null;
            this.lblMasLoc.AccessibleName = null;
            resources.ApplyResources(this.lblMasLoc, "lblMasLoc");
            this.lblMasLoc.Font = null;
            this.lblMasLoc.ForeColor = System.Drawing.Color.Maroon;
            this.lblMasLoc.Name = "lblMasLoc";
            // 
            // lblCCN
            // 
            this.lblCCN.AccessibleDescription = null;
            this.lblCCN.AccessibleName = null;
            resources.ApplyResources(this.lblCCN, "lblCCN");
            this.lblCCN.Font = null;
            this.lblCCN.ForeColor = System.Drawing.Color.Maroon;
            this.lblCCN.Name = "lblCCN";
            // 
            // btnEdit
            // 
            this.btnEdit.AccessibleDescription = null;
            this.btnEdit.AccessibleName = null;
            resources.ApplyResources(this.btnEdit, "btnEdit");
            this.btnEdit.BackgroundImage = null;
            this.btnEdit.Font = null;
            this.btnEdit.Name = "btnEdit";
            this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
            // 
            // btnClose
            // 
            this.btnClose.AccessibleDescription = null;
            this.btnClose.AccessibleName = null;
            resources.ApplyResources(this.btnClose, "btnClose");
            this.btnClose.BackgroundImage = null;
            this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnClose.Font = null;
            this.btnClose.Name = "btnClose";
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // btnHelp
            // 
            this.btnHelp.AccessibleDescription = null;
            this.btnHelp.AccessibleName = null;
            resources.ApplyResources(this.btnHelp, "btnHelp");
            this.btnHelp.BackgroundImage = null;
            this.btnHelp.Font = null;
            this.btnHelp.Name = "btnHelp";
            // 
            // btnDelete
            // 
            this.btnDelete.AccessibleDescription = null;
            this.btnDelete.AccessibleName = null;
            resources.ApplyResources(this.btnDelete, "btnDelete");
            this.btnDelete.BackgroundImage = null;
            this.btnDelete.Font = null;
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
            // 
            // btnSave
            // 
            this.btnSave.AccessibleDescription = null;
            this.btnSave.AccessibleName = null;
            resources.ApplyResources(this.btnSave, "btnSave");
            this.btnSave.BackgroundImage = null;
            this.btnSave.Font = null;
            this.btnSave.Name = "btnSave";
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // btnAdd
            // 
            this.btnAdd.AccessibleDescription = null;
            this.btnAdd.AccessibleName = null;
            resources.ApplyResources(this.btnAdd, "btnAdd");
            this.btnAdd.BackgroundImage = null;
            this.btnAdd.Font = null;
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnPrint
            // 
            this.btnPrint.AccessibleDescription = null;
            this.btnPrint.AccessibleName = null;
            resources.ApplyResources(this.btnPrint, "btnPrint");
            this.btnPrint.BackgroundImage = null;
            this.btnPrint.Font = null;
            this.btnPrint.Name = "btnPrint";
            this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
            // 
            // lblTransDate
            // 
            this.lblTransDate.AccessibleDescription = null;
            this.lblTransDate.AccessibleName = null;
            resources.ApplyResources(this.lblTransDate, "lblTransDate");
            this.lblTransDate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.lblTransDate.Font = null;
            this.lblTransDate.ForeColor = System.Drawing.Color.Maroon;
            this.lblTransDate.Name = "lblTransDate";
            // 
            // btnRouting
            // 
            this.btnRouting.AccessibleDescription = null;
            this.btnRouting.AccessibleName = null;
            resources.ApplyResources(this.btnRouting, "btnRouting");
            this.btnRouting.BackgroundImage = null;
            this.btnRouting.Font = null;
            this.btnRouting.Name = "btnRouting";
            this.btnRouting.Click += new System.EventHandler(this.btnRouting_Click);
            // 
            // btnBOM
            // 
            this.btnBOM.AccessibleDescription = null;
            this.btnBOM.AccessibleName = null;
            resources.ApplyResources(this.btnBOM, "btnBOM");
            this.btnBOM.BackgroundImage = null;
            this.btnBOM.Font = null;
            this.btnBOM.Name = "btnBOM";
            this.btnBOM.Click += new System.EventHandler(this.btnBOM_Click);
            // 
            // btnCost
            // 
            this.btnCost.AccessibleDescription = null;
            this.btnCost.AccessibleName = null;
            resources.ApplyResources(this.btnCost, "btnCost");
            this.btnCost.BackgroundImage = null;
            this.btnCost.Font = null;
            this.btnCost.Name = "btnCost";
            this.btnCost.Click += new System.EventHandler(this.btnCost_Click);
            // 
            // txtMasterLocation
            // 
            this.txtMasterLocation.AccessibleDescription = null;
            this.txtMasterLocation.AccessibleName = null;
            resources.ApplyResources(this.txtMasterLocation, "txtMasterLocation");
            this.txtMasterLocation.BackgroundImage = null;
            this.txtMasterLocation.Font = null;
            this.txtMasterLocation.Name = "txtMasterLocation";
            this.txtMasterLocation.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMasterLocation_KeyDown);
            this.txtMasterLocation.Validating += new System.ComponentModel.CancelEventHandler(this.txtMasterLocation_Validating);
            // 
            // btnSearchMasLoc
            // 
            this.btnSearchMasLoc.AccessibleDescription = null;
            this.btnSearchMasLoc.AccessibleName = null;
            resources.ApplyResources(this.btnSearchMasLoc, "btnSearchMasLoc");
            this.btnSearchMasLoc.BackgroundImage = null;
            this.btnSearchMasLoc.Font = null;
            this.btnSearchMasLoc.Name = "btnSearchMasLoc";
            this.btnSearchMasLoc.Click += new System.EventHandler(this.btnSearchMasLoc_Click);
            // 
            // dtmTransDate
            // 
            resources.ApplyResources(this.dtmTransDate, "dtmTransDate");
            this.dtmTransDate.AccessibleDescription = null;
            this.dtmTransDate.AccessibleName = null;
            this.dtmTransDate.BackgroundImage = null;
            // 
            // 
            // 
            this.dtmTransDate.Calendar.AccessibleDescription = null;
            this.dtmTransDate.Calendar.AccessibleName = null;
            this.dtmTransDate.Calendar.BackgroundImage = null;
            this.dtmTransDate.Calendar.BackgroundImageLayout = ((System.Windows.Forms.ImageLayout)(resources.GetObject("dtmTransDate.Calendar.BackgroundImageLayout")));
            this.dtmTransDate.Calendar.FirstDayOfWeek = ((System.Windows.Forms.Day)(resources.GetObject("dtmTransDate.Calendar.FirstDayOfWeek")));
            this.dtmTransDate.Calendar.Font = null;
            this.dtmTransDate.Calendar.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("dtmTransDate.Calendar.ImeMode")));
            this.dtmTransDate.Calendar.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("dtmTransDate.Calendar.RightToLeft")));
            this.dtmTransDate.Calendar.RightToLeftLayout = ((bool)(resources.GetObject("dtmTransDate.Calendar.RightToLeftLayout")));
            this.dtmTransDate.Calendar.ShowClearButton = ((bool)(resources.GetObject("dtmTransDate.Calendar.ShowClearButton")));
            this.dtmTransDate.Calendar.ShowTodayButton = ((bool)(resources.GetObject("dtmTransDate.Calendar.ShowTodayButton")));
            this.dtmTransDate.Calendar.ShowWeekNumbers = ((bool)(resources.GetObject("dtmTransDate.Calendar.ShowWeekNumbers")));
            this.dtmTransDate.DisplayFormat.Inherit = ((C1.Win.C1Input.FormatInfoInheritFlags)(resources.GetObject("dtmTransDate.DisplayFormat.Inherit")));
            this.dtmTransDate.EditFormat.Inherit = ((C1.Win.C1Input.FormatInfoInheritFlags)(resources.GetObject("dtmTransDate.EditFormat.Inherit")));
            this.dtmTransDate.EditMask = null;
            this.dtmTransDate.ErrorInfo.BeepOnError = ((bool)(resources.GetObject("dtmTransDate.ErrorInfo.BeepOnError")));
            this.dtmTransDate.ErrorInfo.ErrorMessage = resources.GetString("dtmTransDate.ErrorInfo.ErrorMessage");
            this.dtmTransDate.ErrorInfo.ErrorMessageCaption = resources.GetString("dtmTransDate.ErrorInfo.ErrorMessageCaption");
            this.dtmTransDate.ErrorInfo.ShowErrorMessage = ((bool)(resources.GetObject("dtmTransDate.ErrorInfo.ShowErrorMessage")));
            this.dtmTransDate.Font = null;
            this.dtmTransDate.MaskInfo.AutoTabWhenFilled = ((bool)(resources.GetObject("dtmTransDate.MaskInfo.AutoTabWhenFilled")));
            this.dtmTransDate.MaskInfo.Inherit = ((C1.Win.C1Input.MaskInfoInheritFlags)(resources.GetObject("dtmTransDate.MaskInfo.Inherit")));
            this.dtmTransDate.MaskInfo.PromptChar = ((char)(resources.GetObject("dtmTransDate.MaskInfo.PromptChar")));
            this.dtmTransDate.MaskInfo.ShowLiterals = ((C1.Win.C1Input.ShowLiteralsEnum)(resources.GetObject("dtmTransDate.MaskInfo.ShowLiterals")));
            this.dtmTransDate.MaskInfo.StoredEmptyChar = ((char)(resources.GetObject("dtmTransDate.MaskInfo.StoredEmptyChar")));
            this.dtmTransDate.Name = "dtmTransDate";
            this.dtmTransDate.ParseInfo.DateTimeStyle = ((C1.Win.C1Input.DateTimeStyleFlags)(resources.GetObject("dtmTransDate.ParseInfo.DateTimeStyle")));
            this.dtmTransDate.ParseInfo.Inherit = ((C1.Win.C1Input.ParseInfoInheritFlags)(resources.GetObject("dtmTransDate.ParseInfo.Inherit")));
            this.dtmTransDate.PostValidation.Inherit = ((C1.Win.C1Input.PostValidationInheritFlags)(resources.GetObject("dtmTransDate.PostValidation.Inherit")));
            this.dtmTransDate.PostValidation.Validation = ((C1.Win.C1Input.PostValidationTypeEnum)(resources.GetObject("dtmTransDate.PostValidation.Validation")));
            this.dtmTransDate.PreValidation.Inherit = ((C1.Win.C1Input.PreValidationInheritFlags)(resources.GetObject("dtmTransDate.PreValidation.Inherit")));
            this.dtmTransDate.PreValidation.ItemSeparator = resources.GetString("dtmTransDate.PreValidation.ItemSeparator");
            this.dtmTransDate.PreValidation.PatternString = resources.GetString("dtmTransDate.PreValidation.PatternString");
            this.dtmTransDate.PreValidation.RegexOptions = ((C1.Win.C1Input.RegexOptionFlags)(resources.GetObject("dtmTransDate.PreValidation.RegexOptions")));
            this.dtmTransDate.PreValidation.Validation = ((C1.Win.C1Input.PreValidationTypeEnum)(resources.GetObject("dtmTransDate.PreValidation.Validation")));
            this.dtmTransDate.Tag = null;
            this.dtmTransDate.Leave += new System.EventHandler(this.OnLeaveControl);
            this.dtmTransDate.Enter += new System.EventHandler(this.OnEnterControl);
            this.dtmTransDate.DropDownClosed += new DropDownClosedEventHandler(this.dtmTransDate_DropDownClosed);
            // 
            // cboCCN
            // 
            this.cboCCN.AccessibleDescription = null;
            this.cboCCN.AccessibleName = null;
            this.cboCCN.AddItemSeparator = ';';
            this.cboCCN.AllowRowSizing = C1.Win.C1List.RowSizingEnum.AllRows;
            resources.ApplyResources(this.cboCCN, "cboCCN");
            this.cboCCN.BackgroundImage = null;
            this.cboCCN.Caption = "";
            this.cboCCN.CaptionHeight = 17;
            this.cboCCN.CaptionStyle = style35;
            this.cboCCN.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal;
            this.cboCCN.ColumnCaptionHeight = 17;
            this.cboCCN.ColumnFooterHeight = 17;
            this.cboCCN.ComboStyle = C1.Win.C1List.ComboStyleEnum.DropdownList;
            this.cboCCN.ContentHeight = 15;
            this.cboCCN.DeadAreaBackColor = System.Drawing.Color.Empty;
            this.cboCCN.EditorBackColor = System.Drawing.SystemColors.Window;
            this.cboCCN.EditorFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cboCCN.EditorForeColor = System.Drawing.SystemColors.WindowText;
            this.cboCCN.EditorHeight = 15;
            this.cboCCN.EvenRowStyle = style36;
            this.cboCCN.FlatStyle = C1.Win.C1List.FlatModeEnum.System;
            this.cboCCN.Font = null;
            this.cboCCN.FooterStyle = style37;
            this.cboCCN.GapHeight = 2;
            this.cboCCN.HeadingStyle = style38;
            this.cboCCN.HighLightRowStyle = style39;
            this.cboCCN.ItemHeight = 15;
            this.cboCCN.MatchEntryTimeout = ((long)(2000));
            this.cboCCN.MaxDropDownItems = ((short)(5));
            this.cboCCN.MaxLength = 32767;
            this.cboCCN.MouseCursor = System.Windows.Forms.Cursors.Default;
            this.cboCCN.Name = "cboCCN";
            this.cboCCN.OddRowStyle = style40;
            this.cboCCN.PartialRightColumn = false;
            this.cboCCN.RowDivider.Color = System.Drawing.Color.DarkGray;
            this.cboCCN.RowDivider.Style = C1.Win.C1List.LineStyleEnum.None;
            this.cboCCN.RowSubDividerColor = System.Drawing.Color.DarkGray;
            this.cboCCN.SelectedStyle = style41;
            this.cboCCN.Style = style42;
            this.cboCCN.Leave += new System.EventHandler(this.OnLeaveControl);
            this.cboCCN.Enter += new System.EventHandler(this.OnEnterControl);
            this.cboCCN.PropBag = resources.GetString("cboCCN.PropBag");
            // 
            // dtmDate
            // 
            resources.ApplyResources(this.dtmDate, "dtmDate");
            this.dtmDate.AccessibleDescription = null;
            this.dtmDate.AccessibleName = null;
            this.dtmDate.BackgroundImage = null;
            // 
            // 
            // 
            this.dtmDate.Calendar.AccessibleDescription = null;
            this.dtmDate.Calendar.AccessibleName = null;
            this.dtmDate.Calendar.BackgroundImage = null;
            this.dtmDate.Calendar.BackgroundImageLayout = ((System.Windows.Forms.ImageLayout)(resources.GetObject("dtmDate.Calendar.BackgroundImageLayout")));
            this.dtmDate.Calendar.FirstDayOfWeek = ((System.Windows.Forms.Day)(resources.GetObject("dtmDate.Calendar.FirstDayOfWeek")));
            this.dtmDate.Calendar.Font = null;
            this.dtmDate.Calendar.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("dtmDate.Calendar.ImeMode")));
            this.dtmDate.Calendar.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("dtmDate.Calendar.RightToLeft")));
            this.dtmDate.Calendar.RightToLeftLayout = ((bool)(resources.GetObject("dtmDate.Calendar.RightToLeftLayout")));
            this.dtmDate.Calendar.ShowClearButton = ((bool)(resources.GetObject("dtmDate.Calendar.ShowClearButton")));
            this.dtmDate.Calendar.ShowTodayButton = ((bool)(resources.GetObject("dtmDate.Calendar.ShowTodayButton")));
            this.dtmDate.Calendar.ShowWeekNumbers = ((bool)(resources.GetObject("dtmDate.Calendar.ShowWeekNumbers")));
            this.dtmDate.DisplayFormat.Inherit = ((C1.Win.C1Input.FormatInfoInheritFlags)(resources.GetObject("dtmDate.DisplayFormat.Inherit")));
            this.dtmDate.EditFormat.Inherit = ((C1.Win.C1Input.FormatInfoInheritFlags)(resources.GetObject("dtmDate.EditFormat.Inherit")));
            this.dtmDate.EditMask = null;
            this.dtmDate.ErrorInfo.BeepOnError = ((bool)(resources.GetObject("dtmDate.ErrorInfo.BeepOnError")));
            this.dtmDate.ErrorInfo.ErrorMessage = resources.GetString("dtmDate.ErrorInfo.ErrorMessage");
            this.dtmDate.ErrorInfo.ErrorMessageCaption = resources.GetString("dtmDate.ErrorInfo.ErrorMessageCaption");
            this.dtmDate.ErrorInfo.ShowErrorMessage = ((bool)(resources.GetObject("dtmDate.ErrorInfo.ShowErrorMessage")));
            this.dtmDate.Font = null;
            this.dtmDate.MaskInfo.AutoTabWhenFilled = ((bool)(resources.GetObject("dtmDate.MaskInfo.AutoTabWhenFilled")));
            this.dtmDate.MaskInfo.Inherit = ((C1.Win.C1Input.MaskInfoInheritFlags)(resources.GetObject("dtmDate.MaskInfo.Inherit")));
            this.dtmDate.MaskInfo.PromptChar = ((char)(resources.GetObject("dtmDate.MaskInfo.PromptChar")));
            this.dtmDate.MaskInfo.ShowLiterals = ((C1.Win.C1Input.ShowLiteralsEnum)(resources.GetObject("dtmDate.MaskInfo.ShowLiterals")));
            this.dtmDate.MaskInfo.StoredEmptyChar = ((char)(resources.GetObject("dtmDate.MaskInfo.StoredEmptyChar")));
            this.dtmDate.Name = "dtmDate";
            this.dtmDate.ParseInfo.DateTimeStyle = ((C1.Win.C1Input.DateTimeStyleFlags)(resources.GetObject("dtmDate.ParseInfo.DateTimeStyle")));
            this.dtmDate.ParseInfo.Inherit = ((C1.Win.C1Input.ParseInfoInheritFlags)(resources.GetObject("dtmDate.ParseInfo.Inherit")));
            this.dtmDate.PostValidation.Inherit = ((C1.Win.C1Input.PostValidationInheritFlags)(resources.GetObject("dtmDate.PostValidation.Inherit")));
            this.dtmDate.PostValidation.Validation = ((C1.Win.C1Input.PostValidationTypeEnum)(resources.GetObject("dtmDate.PostValidation.Validation")));
            this.dtmDate.PreValidation.Inherit = ((C1.Win.C1Input.PreValidationInheritFlags)(resources.GetObject("dtmDate.PreValidation.Inherit")));
            this.dtmDate.PreValidation.ItemSeparator = resources.GetString("dtmDate.PreValidation.ItemSeparator");
            this.dtmDate.PreValidation.PatternString = resources.GetString("dtmDate.PreValidation.PatternString");
            this.dtmDate.PreValidation.RegexOptions = ((C1.Win.C1Input.RegexOptionFlags)(resources.GetObject("dtmDate.PreValidation.RegexOptions")));
            this.dtmDate.PreValidation.Validation = ((C1.Win.C1Input.PreValidationTypeEnum)(resources.GetObject("dtmDate.PreValidation.Validation")));
            this.dtmDate.Tag = null;
            this.dtmDate.Enter += new System.EventHandler(this.dtmDate_Enter);
            this.dtmDate.DropDownClosed += new DropDownClosedEventHandler(this.dtmDate_DropDownClosed);
            this.dtmDate.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dtmDate_KeyDown);
            // 
            // txtProductionLine
            // 
            this.txtProductionLine.AccessibleDescription = null;
            this.txtProductionLine.AccessibleName = null;
            resources.ApplyResources(this.txtProductionLine, "txtProductionLine");
            this.txtProductionLine.BackgroundImage = null;
            this.txtProductionLine.Font = null;
            this.txtProductionLine.Name = "txtProductionLine";
            this.txtProductionLine.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtProductionLine_KeyDown);
            this.txtProductionLine.Validating += new System.ComponentModel.CancelEventHandler(this.txtProductionLine_Validating);
            // 
            // lblProductionLine
            // 
            this.lblProductionLine.AccessibleDescription = null;
            this.lblProductionLine.AccessibleName = null;
            resources.ApplyResources(this.lblProductionLine, "lblProductionLine");
            this.lblProductionLine.Font = null;
            this.lblProductionLine.ForeColor = System.Drawing.Color.Maroon;
            this.lblProductionLine.Name = "lblProductionLine";
            // 
            // btnProductionLine
            // 
            this.btnProductionLine.AccessibleDescription = null;
            this.btnProductionLine.AccessibleName = null;
            resources.ApplyResources(this.btnProductionLine, "btnProductionLine");
            this.btnProductionLine.BackgroundImage = null;
            this.btnProductionLine.Font = null;
            this.btnProductionLine.Name = "btnProductionLine";
            this.btnProductionLine.Click += new System.EventHandler(this.btnProductionLine_Click);
            // 
            // lblWorkOrderReport
            // 
            this.lblWorkOrderReport.AccessibleDescription = null;
            this.lblWorkOrderReport.AccessibleName = null;
            resources.ApplyResources(this.lblWorkOrderReport, "lblWorkOrderReport");
            this.lblWorkOrderReport.Font = null;
            this.lblWorkOrderReport.Name = "lblWorkOrderReport";
            // 
            // txtDCPCycle
            // 
            this.txtDCPCycle.AccessibleDescription = null;
            this.txtDCPCycle.AccessibleName = null;
            resources.ApplyResources(this.txtDCPCycle, "txtDCPCycle");
            this.txtDCPCycle.BackgroundImage = null;
            this.txtDCPCycle.Font = null;
            this.txtDCPCycle.Name = "txtDCPCycle";
            this.txtDCPCycle.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDCPCycle_KeyDown);
            this.txtDCPCycle.Validating += new System.ComponentModel.CancelEventHandler(this.txtDCPCycle_Validating);
            // 
            // lblDCPCycle
            // 
            this.lblDCPCycle.AccessibleDescription = null;
            this.lblDCPCycle.AccessibleName = null;
            resources.ApplyResources(this.lblDCPCycle, "lblDCPCycle");
            this.lblDCPCycle.Font = null;
            this.lblDCPCycle.ForeColor = System.Drawing.Color.Black;
            this.lblDCPCycle.Name = "lblDCPCycle";
            // 
            // btnDCPCycle
            // 
            this.btnDCPCycle.AccessibleDescription = null;
            this.btnDCPCycle.AccessibleName = null;
            resources.ApplyResources(this.btnDCPCycle, "btnDCPCycle");
            this.btnDCPCycle.BackgroundImage = null;
            this.btnDCPCycle.Font = null;
            this.btnDCPCycle.Name = "btnDCPCycle";
            this.btnDCPCycle.Click += new System.EventHandler(this.btnDCPCycle_Click);
            // 
            // txtDCPDescription
            // 
            this.txtDCPDescription.AccessibleDescription = null;
            this.txtDCPDescription.AccessibleName = null;
            resources.ApplyResources(this.txtDCPDescription, "txtDCPDescription");
            this.txtDCPDescription.BackgroundImage = null;
            this.txtDCPDescription.Font = null;
            this.txtDCPDescription.Name = "txtDCPDescription";
            this.txtDCPDescription.ReadOnly = true;
            // 
            // txtFGoodsCode
            // 
            this.txtFGoodsCode.AccessibleDescription = null;
            this.txtFGoodsCode.AccessibleName = null;
            resources.ApplyResources(this.txtFGoodsCode, "txtFGoodsCode");
            this.txtFGoodsCode.BackgroundImage = null;
            this.txtFGoodsCode.Font = null;
            this.txtFGoodsCode.Name = "txtFGoodsCode";
            this.txtFGoodsCode.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtFGoodsCode_KeyDown);
            this.txtFGoodsCode.Validating += new System.ComponentModel.CancelEventHandler(this.txtFGoodsCode_Validating);
            // 
            // txtSaleOrderCode
            // 
            this.txtSaleOrderCode.AccessibleDescription = null;
            this.txtSaleOrderCode.AccessibleName = null;
            resources.ApplyResources(this.txtSaleOrderCode, "txtSaleOrderCode");
            this.txtSaleOrderCode.BackgroundImage = null;
            this.txtSaleOrderCode.Font = null;
            this.txtSaleOrderCode.Name = "txtSaleOrderCode";
            this.txtSaleOrderCode.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSaleOrderCode_KeyDown);
            this.txtSaleOrderCode.Validating += new System.ComponentModel.CancelEventHandler(this.txtSaleOrderCode_Validating);
            // 
            // lblFGoodsCode
            // 
            this.lblFGoodsCode.AccessibleDescription = null;
            this.lblFGoodsCode.AccessibleName = null;
            resources.ApplyResources(this.lblFGoodsCode, "lblFGoodsCode");
            this.lblFGoodsCode.Font = null;
            this.lblFGoodsCode.Name = "lblFGoodsCode";
            this.lblFGoodsCode.Tag = "0";
            // 
            // btnFGoodsCode
            // 
            this.btnFGoodsCode.AccessibleDescription = null;
            this.btnFGoodsCode.AccessibleName = null;
            resources.ApplyResources(this.btnFGoodsCode, "btnFGoodsCode");
            this.btnFGoodsCode.BackgroundImage = null;
            this.btnFGoodsCode.Font = null;
            this.btnFGoodsCode.Name = "btnFGoodsCode";
            this.btnFGoodsCode.Click += new System.EventHandler(this.btnFGoodsCode_Click);
            // 
            // lblSaleOrderCode
            // 
            this.lblSaleOrderCode.AccessibleDescription = null;
            this.lblSaleOrderCode.AccessibleName = null;
            resources.ApplyResources(this.lblSaleOrderCode, "lblSaleOrderCode");
            this.lblSaleOrderCode.Font = null;
            this.lblSaleOrderCode.Name = "lblSaleOrderCode";
            this.lblSaleOrderCode.Tag = "0";
            // 
            // btnSaleOrderCode
            // 
            this.btnSaleOrderCode.AccessibleDescription = null;
            this.btnSaleOrderCode.AccessibleName = null;
            resources.ApplyResources(this.btnSaleOrderCode, "btnSaleOrderCode");
            this.btnSaleOrderCode.BackgroundImage = null;
            this.btnSaleOrderCode.Font = null;
            this.btnSaleOrderCode.Name = "btnSaleOrderCode";
            this.btnSaleOrderCode.Click += new System.EventHandler(this.btnSaleOrderCode_Click);
            // 
            // btnPrintWOLine
            // 
            this.btnPrintWOLine.AccessibleDescription = null;
            this.btnPrintWOLine.AccessibleName = null;
            resources.ApplyResources(this.btnPrintWOLine, "btnPrintWOLine");
            this.btnPrintWOLine.BackgroundImage = null;
            this.btnPrintWOLine.Font = null;
            this.btnPrintWOLine.Name = "btnPrintWOLine";
            this.btnPrintWOLine.Click += new System.EventHandler(this.btnPrintWOLine_Click);
            // 
            // btnEditBOM
            // 
            this.btnEditBOM.AccessibleDescription = null;
            this.btnEditBOM.AccessibleName = null;
            resources.ApplyResources(this.btnEditBOM, "btnEditBOM");
            this.btnEditBOM.BackgroundImage = null;
            this.btnEditBOM.Font = null;
            this.btnEditBOM.Name = "btnEditBOM";
            this.btnEditBOM.Click += new System.EventHandler(this.btnEditBOM_Click);
            // 
            // btnSuaBSX
            // 
            this.btnSuaBSX.AccessibleDescription = null;
            this.btnSuaBSX.AccessibleName = null;
            resources.ApplyResources(this.btnSuaBSX, "btnSuaBSX");
            this.btnSuaBSX.BackgroundImage = null;
            this.btnSuaBSX.Font = null;
            this.btnSuaBSX.Name = "btnSuaBSX";
            this.btnSuaBSX.Click += new System.EventHandler(this.btnSuaBSX_Click);
            // 
            // WorkOrder
            // 
            this.AccessibleDescription = null;
            this.AccessibleName = null;
            resources.ApplyResources(this, "$this");
            this.BackgroundImage = null;
            this.CancelButton = this.btnClose;
            this.Controls.Add(this.btnPrintWOLine);
            this.Controls.Add(this.txtFGoodsCode);
            this.Controls.Add(this.txtSaleOrderCode);
            this.Controls.Add(this.txtDCPDescription);
            this.Controls.Add(this.txtDCPCycle);
            this.Controls.Add(this.txtProductionLine);
            this.Controls.Add(this.txtMasterLocation);
            this.Controls.Add(this.txtDescription);
            this.Controls.Add(this.txtWONo);
            this.Controls.Add(this.dgrdData);
            this.Controls.Add(this.lblFGoodsCode);
            this.Controls.Add(this.btnFGoodsCode);
            this.Controls.Add(this.lblSaleOrderCode);
            this.Controls.Add(this.btnSaleOrderCode);
            this.Controls.Add(this.lblDCPCycle);
            this.Controls.Add(this.btnDCPCycle);
            this.Controls.Add(this.lblWorkOrderReport);
            this.Controls.Add(this.lblProductionLine);
            this.Controls.Add(this.btnProductionLine);
            this.Controls.Add(this.cboCCN);
            this.Controls.Add(this.dtmTransDate);
            this.Controls.Add(this.btnSearchMasLoc);
            this.Controls.Add(this.lblTransDate);
            this.Controls.Add(this.btnHelp);
            this.Controls.Add(this.btnDelete);
            this.Controls.Add(this.btnSave);
            this.Controls.Add(this.btnAdd);
            this.Controls.Add(this.btnPrint);
            this.Controls.Add(this.btnEdit);
            this.Controls.Add(this.btnClose);
            this.Controls.Add(this.lblDescription);
            this.Controls.Add(this.lblWO_No);
            this.Controls.Add(this.lblMasLoc);
            this.Controls.Add(this.lblCCN);
            this.Controls.Add(this.btnSearchWO);
            this.Controls.Add(this.chkManufacture);
            this.Controls.Add(this.chkFinance);
            this.Controls.Add(this.btnBOM);
            this.Controls.Add(this.btnCost);
            this.Controls.Add(this.btnSuaBSX);
            this.Controls.Add(this.btnRouting);
            this.Controls.Add(this.dtmDate);
            this.Controls.Add(this.btnEditBOM);
            this.Font = null;
            this.Icon = null;
            this.KeyPreview = true;
            this.Name = "WorkOrder";
            this.Load += new System.EventHandler(this.WorkOrder_Load);
            this.Closing += new System.ComponentModel.CancelEventHandler(this.WorkOrder_Closing);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.WorkOrder_KeyDown);
            ((System.ComponentModel.ISupportInitialize)(this.dgrdData)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dtmTransDate)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.cboCCN)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dtmDate)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion

        /// <summary>
        /// Check user's permission
        /// After that : Reset Form
        /// After that : Load CCN and set default
        /// After that : Switch form's mode
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WorkOrder_Load(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".WorkOrder_Load()";
            try
            {
                Security objSecurity = new Security();
                this.Name = THIS;
                if (objSecurity.SetRightForUserOnForm(this, SystemProperty.UserName) == 0)
                {
                    this.Close();
                    PCSMessageBox.Show(ErrorCode.MESSAGE_YOU_HAVE_NO_RIGHT_TO_VIEW, MessageBoxIcon.Warning);
                    return;
                }


                //Load CCN and set default CCN
                UtilsBO boUtils = new UtilsBO();
                DataSet dstCCN = boUtils.ListCCN();
                cboCCN.DataSource = dstCCN.Tables[MST_CCNTable.TABLE_NAME];
                cboCCN.DisplayMember = MST_CCNTable.CODE_FLD;
                cboCCN.ValueMember = MST_CCNTable.CCNID_FLD;

                FormControlComponents.PutDataIntoC1ComboBox(cboCCN, dstCCN.Tables[MST_CCNTable.TABLE_NAME], MST_CCNTable.CODE_FLD, MST_CCNTable.CCNID_FLD, MST_CCNTable.TABLE_NAME);

                //get grid layout
                dtbGridLayOut = FormControlComponents.StoreGridLayout(dgrdData);

                if (SystemProperty.CCNID != 0)
                {
                    cboCCN.SelectedValue = SystemProperty.CCNID;
                }

                if (mWOFormState == WOFormState.CPOExistWO)
                {
                    FormLoadForExistWOForCPO();
                    return;
                }

                if (voWorkOrderMaster.WorkOrderMasterID != 0)
                {
                    dtbGridLayOut = FormControlComponents.StoreGridLayout(dgrdData);
                    if (voMasLoc.MasterLocationID != 0)
                    {
                        DataRowView drwResult = FormControlComponents.OpenSearchForm("v_PROWorkOrderMasterJoinSaleOrderDetail", PRO_WorkOrderMasterTable.WORKORDERMASTERID_FLD, voWorkOrderMaster.WorkOrderMasterID.ToString(), null, false);
                        FillWOData(drwResult.Row);
                    }
                    else
                        FillWOData(voWorkOrderMaster.WorkOrderMasterID);
                    mFormMode = EnumAction.Default;
                }
                else
                {
                    ResetForm();
                }
                SwitchFormMode();
                //Set default Master Location
                if (txtMasterLocation.Text.Trim() == string.Empty)
                {
                    FormControlComponents.SetDefaultMasterLocation(txtMasterLocation);
                    voMasLoc.MasterLocationID = SystemProperty.MasterLocationID;
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }


        /// <summary>
        /// Create the template data set which 
        /// </summary>
        private void CreateDataSet()
        {
            dstGridData = new DataSet();
            dstGridData.Tables.Add(PRO_WorkOrderDetailTable.TABLE_NAME);

            //insert columns which is invisible but use to update
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.WORKORDERMASTERID_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.SALEORDERDETAILID_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(ITM_ProductTable.PRODUCTID_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.MFGCLOSEDATE_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.FINCLOSEDATE_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.PRIORITY_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.STOCKUMID_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.STATUS_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.AGC_FLD);
            // added: dungla for WORouting
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.PRODUCTIONLINEID_FLD);

            //insert display columns
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.LINE_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(ITM_ProductTable.CODE_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(ITM_ProductTable.REVISION_FLD);

            //HACK: added by Tuan TQ. 23 May, 2006. Add Category column
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(ITM_CategoryTable.TABLE_NAME + ITM_CategoryTable.CODE_FLD);
            //End hack

            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(UM);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD, typeof(Decimal));
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(STATUS_STRING);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.DESCRIPTION_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.STARTDATE_FLD, typeof(DateTime));
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.DUEDATE_FLD, typeof(DateTime));
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(SALE_ORDER_CODE);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(SO_SaleOrderDetailTable.FGOODSCODE_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(ITM_ProductTable.COSTMETHOD_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.ESTCST_FLD, typeof(decimal));
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(AGC_CODE);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.GROUP1_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.GROUP2_FLD);
            dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME].Columns.Add(PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD, typeof(decimal));
        }


        /// <summary>
        /// Config grid layout : lock column, set control to columns...
        /// </summary>
        /// <param name="pblnLock">which specifies that grid's locked or unlocked</param>
        private void ConfigGrid(bool pblnLock)
        {
            dgrdData.Enabled = true;
            for (int i = 0; i < dgrdData.Splits[0].DisplayColumns.Count; i++)
                dgrdData.Splits[0].DisplayColumns[i].Locked = true;
            dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.CODE_FLD].Locked = pblnLock;
            dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD].Locked = pblnLock;
            dgrdData.Splits[0].DisplayColumns[PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD].Locked = pblnLock;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD].Locked = pblnLock;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.STARTDATE_FLD].Locked = pblnLock;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.DUEDATE_FLD].Locked = pblnLock;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.GROUP1_FLD].Locked = pblnLock;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.GROUP2_FLD].Locked = pblnLock;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD].Locked = pblnLock;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD].DataColumn.NumberFormat = Constants.DECIMAL_NUMBERFORMAT;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD].DataColumn.NumberFormat = Constants.DECIMAL_NUMBERFORMAT;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD].Style.HorizontalAlignment = AlignHorzEnum.Far;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD].Style.HorizontalAlignment = AlignHorzEnum.Far;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.STARTDATE_FLD].Style.HorizontalAlignment = AlignHorzEnum.Center;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.DUEDATE_FLD].Style.HorizontalAlignment = AlignHorzEnum.Center;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.LINE_FLD].Style.HorizontalAlignment = AlignHorzEnum.Far;
            dgrdData.Columns[PRO_WorkOrderDetailTable.STARTDATE_FLD].Editor = dtmDate;
            dgrdData.Columns[PRO_WorkOrderDetailTable.STARTDATE_FLD].NumberFormat = Constants.DATETIME_FORMAT_HOUR;
            dgrdData.Columns[PRO_WorkOrderDetailTable.DUEDATE_FLD].Editor = dtmDate;
            dgrdData.Columns[PRO_WorkOrderDetailTable.DUEDATE_FLD].NumberFormat = Constants.DATETIME_FORMAT_HOUR;
            dgrdData.Columns[PRO_WorkOrderDetailTable.ESTCST_FLD].NumberFormat = Constants.DECIMAL_NUMBERFORMAT;
            if (!pblnLock)
            {
                dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.CODE_FLD].Button = true;
                dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD].Button = true;
                dgrdData.Splits[0].DisplayColumns[PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD].Button = true;
            }
        }


        /// <summary>
        /// Search Master Location by CCN
        /// </summary>
        ///	<author>
        ///	Do Manh Tuan
        ///	Thursday, June. 2. 2005
        ///	</author>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearchMasLoc_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnSearchMasLoc_Click()";
            try
            {
                DataRowView drwResult = null;
                Hashtable htbCondition = new Hashtable();

                if (cboCCN.SelectedValue != null)
                {
                    htbCondition.Add(MST_MasterLocationTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                }
                else
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_RGA_CCN, MessageBoxIcon.Warning);
                    cboCCN.Focus();
                    return;
                }
                drwResult = FormControlComponents.OpenSearchForm(MST_MasterLocationTable.TABLE_NAME, MST_MasterLocationTable.CODE_FLD, txtMasterLocation.Text, htbCondition, true);
                if (drwResult != null)
                {
                    txtMasterLocation.Text = drwResult[MST_MasterLocationTable.CODE_FLD].ToString();
                    voMasLoc.MasterLocationID = int.Parse(drwResult[MST_MasterLocationTable.MASTERLOCATIONID_FLD].ToString());
                    if ((voMasLoc.MasterLocationID != voWorkOrderMaster.MasterLocationID) && (voWorkOrderMaster.MasterLocationID != 0))
                    {
                        ResetFormIfMasLocChanged();
                    }
                }
                else
                {
                    txtMasterLocation.Focus();
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }


        /// <summary>
        /// Search WO event:
        ///		Open the search form to search WO by WONo
        /// </summary>
        /// <author>
        /// Do Manh Tuan
        /// Thursday, Jun - 2 -2005
        /// </author>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearchWO_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnSearchWO_Click()";
            try
            {
                DataRowView drwResult = null;
                Hashtable htbCondition = new Hashtable();
                if (txtMasterLocation.Text.Trim() == string.Empty)
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_RGA_MASTERLOCATION, MessageBoxIcon.Warning);
                    txtMasterLocation.Focus();
                    return;
                }
                if (cboCCN.SelectedValue != null)
                {
                    htbCondition.Add(PRO_WorkOrderMasterTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                    htbCondition.Add(PRO_WorkOrderMasterTable.MASTERLOCATIONID_FLD, voMasLoc.MasterLocationID);
                }
                drwResult = FormControlComponents.OpenSearchForm("v_PROWorkOrderMasterJoinSaleOrderDetail", PRO_WorkOrderMasterTable.WORKORDERNO_FLD, txtWONo.Text, htbCondition, true);
                if (drwResult != null)
                    FillWOData(drwResult.Row);
                else
                    txtWONo.Focus();
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }


        /// <summary>
        /// Add event :
        ///		Reset form()
        ///		Change form's mode
        ///		Select data and unlock grid
        /// </summary>
        ///	<author>
        ///		Do Manh Tuan
        ///		Thursday, Jun 2 2005
        ///	</author>	
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnAdd_Click()";
            try
            {
                mFormMode = EnumAction.Add;
                ResetForm();
                SwitchFormMode();
                dtmTransDate.Value = new UtilsBO().GetDBDate();
                //txtWONo.Text = new UtilsBO().GetNoByMask(PRO_WorkOrderMasterTable.TABLE_NAME, PRO_WorkOrderMasterTable.WORKORDERNO_FLD,  DateTime.Parse(dtmTransDate.Value.ToString()), string.Empty );						
                txtWONo.Text = FormControlComponents.GetNoByMask(this);
                //Fill Default Master Location 
                FormControlComponents.SetDefaultMasterLocation(txtMasterLocation);
                voMasLoc.MasterLocationID = SystemProperty.MasterLocationID;
                CreateDataSet();
                dgrdData.DataSource = dstGridData.Tables[PRO_WorkOrderDetailTable.TABLE_NAME];
                FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayOut);
                ConfigGrid(false);
                strLastValidPro = string.Empty;
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }


        /// <summary>
        /// Validate all data, and some business rules
        /// </summary>
        /// <returns></returns>
        private bool ValidateData()
        {
            if (FormControlComponents.CheckMandatory(dtmTransDate))
            {
                PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID);
                dtmTransDate.Focus();
                dtmTransDate.Select();
                return false;
            }

            if (FormControlComponents.CheckMandatory(txtMasterLocation))
            {
                PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID);
                txtMasterLocation.Focus();
                txtMasterLocation.Select();
                return false;
            }
            if (FormControlComponents.CheckMandatory(txtWONo))
            {
                PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID);
                txtWONo.Focus();
                txtWONo.Select();
                return false;
            }

            // Update SaleOrderMasterID and SALEORDERDETAILID
            if ((int)lblSaleOrderCode.Tag != 0 && lblSaleOrderCode.Tag.ToString().Trim() != string.Empty)
            {
                foreach (DataRow objRow in dstGridData.Tables[0].Rows)
                {
                    if (objRow.RowState == DataRowState.Deleted)
                        continue;
                    try
                    {
                        if ((int)lblFGoodsCode.Tag != 0)
                        {
                            objRow[SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD] = (int)lblFGoodsCode.Tag;
                            objRow[SO_SaleOrderDetailTable.FGOODSCODE_FLD] = txtFGoodsCode.Text.ToString();
                        }
                        else
                        {
                            PCSMessageBox.Show(ErrorCode.MESSAGE_MUST_SELECT_SALEORDERLINE_FIRST);
                            txtFGoodsCode.Focus();
                            return false;
                        }
                    }
                    catch
                    {
                        objRow[SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD] = DBNull.Value;
                    }

                    try
                    {
                        objRow[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD] = (int)lblSaleOrderCode.Tag;
                        objRow[SALE_ORDER_CODE] = txtSaleOrderCode.Text.ToString();
                    }
                    catch
                    {
                        objRow[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD] = DBNull.Value;
                    }
                }
            }
            //check madatory field in grid
            dgrdData.UpdateData();
            int intRowCount = dgrdData.RowCount;
            if (intRowCount == 0)
            {
                PCSMessageBox.Show(ErrorCode.MESSAGE_WO_HASWOLINE);
                dgrdData.Row = 0;
                dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.CODE_FLD]);
                dgrdData.Focus();
                return false;
            }
            for (int i = 0; i < intRowCount; i++)
            {
                if (dgrdData[i, PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD].ToString() == string.Empty)
                {
                    PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Error);
                    dgrdData.Row = i;
                    dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD]);
                    dgrdData.Focus();
                    return false;
                }
                if (dgrdData[i, ITM_ProductTable.CODE_FLD].ToString() == string.Empty)
                {
                    PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Error);
                    dgrdData.Row = i;
                    dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.CODE_FLD]);
                    dgrdData.Focus();
                    return false;
                }
                if (dgrdData[i, PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD].ToString() == string.Empty)
                {
                    PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Error);
                    dgrdData.Row = i;
                    dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD]);
                    dgrdData.Focus();
                    return false;
                }
                if (dgrdData[i, PRO_WorkOrderDetailTable.STARTDATE_FLD].ToString() == string.Empty)
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_WO_STARTDATE_TRANSDATE, MessageBoxIcon.Error);
                    dgrdData.Row = i;
                    dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.STARTDATE_FLD]);
                    dgrdData.Focus();
                    return false;
                }
                if (dgrdData[i, PRO_WorkOrderDetailTable.DUEDATE_FLD].ToString() == string.Empty)
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_WO_DUEDATE_TRANSDATE, MessageBoxIcon.Error);
                    dgrdData.Row = i;
                    dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.DUEDATE_FLD]);
                    dgrdData.Focus();
                    return false;
                }
            }
            return true;
        }


        /// <summary>
        /// Save event:
        ///		Validate date
        ///		Get data into voWorkOrderMaster
        ///		Sate to database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnSave_Click()";
            try
            {
                blnHasError = true;

                if (!dgrdData.EditActive && ValidateData())
                {
                    // HACK: Trada 13-12-2005
                    if (Security.IsDifferencePrefix(this, lblWO_No, txtWONo))
                        return;
                    // END: Trada 13-12-2005
                    boWorkOrder = new WorkOrderBO();
                    GetDataOfWorkOrderMaster();
                    List<PRO_WorkOrderDetail> listDetail = new List<PRO_WorkOrderDetail>();

                    foreach (DataRow dr in dstGridData.Tables[0].Rows)
                    {
                        if (dr.RowState == DataRowState.Deleted) continue;
                        PRO_WorkOrderDetail obj = new PRO_WorkOrderDetail();
                        if (dr[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD] != null && dr[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD].ToString() != string.Empty)
                            obj.SaleOrderMasterID = Convert.ToInt32(dr[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD]);
                        if (dr[PRO_WorkOrderDetailTable.SALEORDERDETAILID_FLD] != null && dr[PRO_WorkOrderDetailTable.SALEORDERDETAILID_FLD].ToString() != string.Empty)
                            obj.SaleOrderDetailID = Convert.ToInt32(dr[PRO_WorkOrderDetailTable.SALEORDERDETAILID_FLD]);
                        if (dr[PRO_WorkOrderDetailTable.AGC_FLD] != null && dr[PRO_WorkOrderDetailTable.AGC_FLD].ToString() != string.Empty)
                            obj.AGC = Convert.ToDecimal(dr[PRO_WorkOrderDetailTable.AGC_FLD]);
                        obj.Description = dr[PRO_WorkOrderDetailTable.DESCRIPTION_FLD] == null ? string.Empty : dr[PRO_WorkOrderDetailTable.DESCRIPTION_FLD].ToString();
                        obj.DueDate = Convert.ToDateTime(dr[PRO_WorkOrderDetailTable.DUEDATE_FLD]);
                        obj.StartDate = Convert.ToDateTime(dr[PRO_WorkOrderDetailTable.STARTDATE_FLD]);
                        if (dr[PRO_WorkOrderDetailTable.ESTCST_FLD] != null && dr[PRO_WorkOrderDetailTable.ESTCST_FLD].ToString() != string.Empty)
                            obj.EstCst = Convert.ToDecimal(dr[PRO_WorkOrderDetailTable.ESTCST_FLD]);
                        if (dr[PRO_WorkOrderDetailTable.FINCLOSEDATE_FLD] != null && dr[PRO_WorkOrderDetailTable.FINCLOSEDATE_FLD].ToString() != string.Empty)
                            obj.FinCloseDate = Convert.ToDateTime(dr[PRO_WorkOrderDetailTable.FINCLOSEDATE_FLD]);
                        obj.Group1 = dr[PRO_WorkOrderDetailTable.GROUP1_FLD] == null ? string.Empty : dr[PRO_WorkOrderDetailTable.GROUP1_FLD].ToString();
                        obj.Group2 = dr[PRO_WorkOrderDetailTable.GROUP2_FLD] == null ? string.Empty : dr[PRO_WorkOrderDetailTable.GROUP2_FLD].ToString();
                        if (dr[PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD] != null && dr[PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD].ToString() != string.Empty)
                            obj.GroupQuantity = Convert.ToDecimal(dr[PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD]);
                        //if (dr[PRO_WorkOrderDetailTable.INCREMENT_FLD] != null && dr[PRO_WorkOrderDetailTable.INCREMENT_FLD].ToString() != string.Empty)
                        //    obj.Increment = Convert.ToInt32(dr[PRO_WorkOrderDetailTable.INCREMENT_FLD]);
                        obj.Line = Convert.ToInt32(dr[PRO_WorkOrderDetailTable.LINE_FLD]);
                        if (dr[PRO_WorkOrderDetailTable.MFGCLOSEDATE_FLD] != null && dr[PRO_WorkOrderDetailTable.MFGCLOSEDATE_FLD].ToString() != string.Empty)
                            obj.MfgCloseDate = Convert.ToDateTime(dr[PRO_WorkOrderDetailTable.MFGCLOSEDATE_FLD]);
                        obj.OrderQuantity = Convert.ToDecimal(dr[PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD]);
                        if (dr[PRO_WorkOrderDetailTable.PRIORITY_FLD] != null && dr[PRO_WorkOrderDetailTable.PRIORITY_FLD].ToString() != string.Empty)
                            obj.Priority = Convert.ToByte(dr[PRO_WorkOrderDetailTable.PRIORITY_FLD]);
                        obj.ProductID = Convert.ToInt32(dr[PRO_WorkOrderDetailTable.PRODUCTID_FLD]);
                        if (dr[PRO_WorkOrderDetailTable.PRODUCTIONLINEID_FLD] != null && dr[PRO_WorkOrderDetailTable.PRODUCTIONLINEID_FLD].ToString() != string.Empty)
                            obj.ProductionLineID = Convert.ToInt32(dr[PRO_WorkOrderDetailTable.PRODUCTIONLINEID_FLD]);
                        obj.StockUMID = Convert.ToInt32(dr[PRO_WorkOrderDetailTable.STOCKUMID_FLD]);
                        if (dr[PRO_WorkOrderDetailTable.STATUS_FLD] != null && dr[PRO_WorkOrderDetailTable.STATUS_FLD].ToString() != string.Empty)
                            obj.Status = Convert.ToByte(dr[PRO_WorkOrderDetailTable.STATUS_FLD]);
                        else obj.Status = 0;
                        listDetail.Add(obj);
                    }
                    if (FormMode == EnumAction.Add)
                    {

                        if (mWOFormState == WOFormState.Normal)
                            //voWorkOrderMaster.WorkOrderMasterID = boWorkOrder.AddAndReturnID(voWorkOrderMaster, dstGridData);
                            boWorkOrder.InsertWorkOrder(voWorkOrderMaster, listDetail,"");
                    }
                    else
                    {
                        if (mWOFormState == WOFormState.Normal)
                            boWorkOrder.UpdateWOAndWOLines(voWorkOrderMaster, dstGridData, ArlWOLineID);
                        //boWorkOrder.UpdateWorkOrder(voWorkOrderMaster, listDetail);
                        else
                        {
                            ArrayList arlCPOIDs = new ArrayList();
                            if (dtwCPOs.Table.TableName == MTR_CPOTable.TABLE_NAME)
                            {
                                foreach (DataRowView drvCPO in dtwCPOs)
                                    arlCPOIDs.Add(drvCPO[MTR_CPOTable.CPOID_FLD].ToString());
                                boWorkOrder.UpdateExistedWOImmediately(dstGridData, voWorkOrderMaster, ArlWOLineID, arlCPOIDs, PlanTypeEnum.MPS.ToString());
                            }
                            else
                            {
                                foreach (DataRowView drvCPO in dtwCPOs)
                                    arlCPOIDs.Add(drvCPO[PRO_DCPResultDetailTable.DCPRESULTDETAILID_FLD].ToString());
                                boWorkOrder.UpdateExistedWOImmediately(dstGridData, voWorkOrderMaster, ArlWOLineID, arlCPOIDs, string.Empty);
                            }

                        }
                    }
                    Security.UpdateUserNameModifyTransaction(this, PRO_WorkOrderMasterTable.WORKORDERMASTERID_FLD, voWorkOrderMaster.WorkOrderMasterID);
                    PCSMessageBox.Show(ErrorCode.MESSAGE_AFTER_SAVE_DATA);
                    FormMode = EnumAction.Default;

                    // HACK: SonHT 2005-12-08
                    SwitchFormMode();
                    // END: SonHT 2005-12-08

                    //reload grid form database
                    dstGridData = boWorkOrder.GetWODetailByMaster(voWorkOrderMaster.WorkOrderMasterID);
                    dgrdData.DataSource = dstGridData.Tables[0];

                    //restore the layout of grid
                    dtmDate.CustomFormat = Constants.DATETIME_FORMAT_HOUR;
                    FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayOut);
                    ConfigGrid(true);
                    btnDelete.Enabled = true;
                    btnSearchWO.Enabled = true;
                    btnEdit.Enabled = true;
                    btnSave.Enabled = false;
                    btnAdd.Enabled = true;
                    blnHasError = false;
                    btnBOM.Enabled = true;
                    btnRouting.Enabled = true;
                    if (CheckWOLines(WOLineStatus.MfgClose))
                        chkManufacture.Checked = true;
                    else
                    {
                        if (CheckWOLines(WOLineStatus.FinClose))
                            chkFinance.Checked = true;
                    }
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                if (ex.mCode == ErrorCode.DUPLICATE_KEY)
                    txtWONo.Focus();
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }


        /// <summary>
        /// Edit event:
        ///		change FormMode
        ///		Reload data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEdit_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnEdit_Click()";
            try
            {
                //				if(Security.NoRightToEditTransaction(this, PRO_WorkOrderMasterTable.WORKORDERMASTERID_FLD, voWorkOrderMaster.WorkOrderMasterID))
                //				{
                //					return;
                //				}
                FormMode = EnumAction.Edit;
                SwitchFormMode();
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }


        private void btnClose_Click(object sender, EventArgs e)
        {
            if (dgrdData.EditActive) return;
            this.Close();
        }

        /// <summary>
        /// Transfer information to WORouting form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRouting_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnRouting_Click()";
            try
            {
                if (dgrdData.Row < dgrdData.RowCount)
                {
                    int intProductionLineID = 0;
                    try
                    {
                        intProductionLineID = int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.PRODUCTIONLINEID_FLD].ToString());
                    }
                    catch { }
                    WORouting frmWORouting = new WORouting(int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString())
                        , int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.PRODUCTID_FLD].ToString())
                        , int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STATUS_FLD].ToString())
                        , int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERMASTERID_FLD].ToString())
                        , intProductionLineID);

                    frmWORouting.ShowDialog();
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }


        /// <summary>
        /// Transfer information to WOBOM form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBOM_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnBOM_Click()";
            try
            {
                if (dgrdData.Row < dgrdData.RowCount)
                {
                    string strFGoodsCode = dgrdData[dgrdData.Row, SO_SaleOrderDetailTable.FGOODSCODE_FLD].ToString();
                    int intWODetailID = Convert.ToInt32(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD]);
                    int intProductID = Convert.ToInt32(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.PRODUCTID_FLD]);
                    int intStatus = Convert.ToInt32(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STATUS_FLD]);
                    WOBOM frmWOBOM = new WOBOM(strFGoodsCode, intWODetailID, intStatus, voWorkOrderMaster.WorkOrderMasterID, voWorkOrderMaster.WorkOrderNo, intProductID);
                    frmWOBOM.ShowDialog();
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// Transfer information to Cost form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCost_Click(object sender, EventArgs e)
        {
        }


        /// <summary>
        /// Delete event:
        ///		Check all work order lines
        ///		Delete WO if all lines are unrelease
        /// </summary>
        /// <author>
        /// Do Manh Tuan
        /// 08-06-2005
        /// </author>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnDelete_Click()";
            try
            {
                if (!dgrdData.EditActive && CheckWOLines(WOLineStatus.Unreleased))
                {
                    //allow deleteS
                    if (PCSMessageBox.Show(ErrorCode.MESSAGE_DELETE_RECORD, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        ////reload grid form database
                        //dstGridData = boWorkOrder.GetWODetailByMaster(voWorkOrderMaster.WorkOrderMasterID);
                        //dgrdData.DataSource = dstGridData.Tables[0];

                        //restore the layout of grid
                        FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayOut);


                        boWorkOrder.DeleteWorkOrder(voWorkOrderMaster.WorkOrderMasterID);
                        FormMode = EnumAction.Default;
                        string strMasLoc = txtMasterLocation.Text.Trim();
                        ResetForm();
                        txtMasterLocation.Text = strMasLoc;
                        SwitchFormMode();
                        CreateDataSet();
                        dgrdData.DataSource = dstGridData.Tables[0];
                        FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayOut);
                        ConfigGrid(true);
                        txtMasterLocation.Text = string.Empty;
                        dtmTransDate.Value = DBNull.Value;
                        txtMasterLocation.Focus();
                        //Set default Master Location
                        FormControlComponents.SetDefaultMasterLocation(txtMasterLocation);
                        voMasLoc.MasterLocationID = SystemProperty.MasterLocationID;
                    }
                }
                else
                {
                    //don't allow detete
                    PCSMessageBox.Show(ErrorCode.MESSAGE_WO_CANNOT_DELWO, MessageBoxIcon.Error);
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// Form Keydown event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WorkOrder_KeyDown(object sender, KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".WorkOrder_KeyDown()";
            try
            {
                if (e.KeyCode == Keys.F12)
                {
                    if (!dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.CODE_FLD].Locked)
                    {
                        dgrdData.Row = dgrdData.RowCount;
                        dgrdData.Col = dgrdData.Columns.IndexOf(dgrdData.Columns[ITM_ProductTable.CODE_FLD]);
                        dgrdData.Focus();
                        dgrdData.EditActive = false;
                    }
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// Keydown event:
        ///		F12 : Add new row into the grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgrdData_KeyDown(object sender, KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_KeyDown()";
            try
            {
                switch (e.KeyCode)
                {
                    case Keys.F4:
                        if (btnSave.Enabled)
                        {
                            dgrdData_ButtonClick(sender, null);
                        }
                        break;
                    case Keys.Delete:
                        if ((e.KeyCode == Keys.Delete) && (dgrdData.SelectedRows.Count > 0))
                        {
                            if (btnSave.Enabled)
                            {
                                //if WO's status is UnRealease
                                if (dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString() != string.Empty)
                                {
                                    dgrdData.AllowDelete = true;
                                    int intSelectRows = dgrdData.SelectedRows.Count;
                                    bool boolWoLineStatus = true;
                                    for (int i = 0; i < intSelectRows; i++)
                                    {
                                        if (int.Parse(dgrdData[int.Parse(dgrdData.SelectedRows[i].ToString()), PRO_WorkOrderDetailTable.STATUS_FLD].ToString()) == (int)WOLineStatus.Unreleased)
                                        {
                                            ArlWOLineID.Add(dgrdData[int.Parse(dgrdData.SelectedRows[i].ToString()), PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString());
                                        }
                                        else
                                            boolWoLineStatus = false;
                                    }

                                    if (boolWoLineStatus)
                                    {
                                        FormControlComponents.DeleteMultiRowsOnTrueDBGrid(dgrdData);
                                    }
                                    //									else
                                    //									{
                                    //										//don't allow detete
                                    //										PCSMessageBox.Show(ErrorCode.MESSAGE_WO_CANNOT_DELWO, MessageBoxIcon.Error);
                                    //									}
                                }
                            }
                        }
                        break;
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// Based on FormMode property to switching form mode
        /// case EnumAction.Default:
        /// case EnumAction.Add:
        /// case EnumAction.Edit:
        /// </summary>
        private void SwitchFormMode()
        {
            switch (mFormMode)
            {
                case EnumAction.Default:
                    btnAdd.Enabled = true;
                    dtmTransDate.Enabled = false;
                    txtDescription.Enabled = false;
                    btnSave.Enabled = false;
                    btnEdit.Enabled = false;
                    btnDelete.Enabled = false;
                    btnBOM.Enabled = false;
                    btnRouting.Enabled = false;
                    btnCost.Enabled = false;
                    dgrdData.AllowDelete = false;
                    btnSearchWO.Enabled = true;
                    ConfigGrid(true);
                    btnPrint.Enabled = false;
                    btnSaleOrderCode.Enabled = false;
                    btnFGoodsCode.Enabled = false;
                    txtSaleOrderCode.Enabled = false;
                    txtFGoodsCode.Enabled = false;
                    if (dgrdData.RowCount > 1)
                    {
                        //check security 
                        btnBOM.Enabled = true;
                        btnRouting.Enabled = true;
                        btnCost.Enabled = true;
                        btnPrintWOLine.Enabled = true;

                        btnEdit.Enabled = true;
                        btnDelete.Enabled = true;
                        btnPrint.Enabled = true;
                    }
                    txtMasterLocation.Enabled = true;
                    btnSearchMasLoc.Enabled = true;
                    btnProductionLine.Enabled = false;
                    txtProductionLine.Enabled = false;
                    btnDCPCycle.Enabled = false;
                    txtDCPCycle.Enabled = false;
                    break;
                case EnumAction.Add:
                    btnAdd.Enabled = false;
                    dtmTransDate.Enabled = true;
                    txtDescription.Enabled = true;
                    btnSave.Enabled = true;
                    btnSearchWO.Enabled = false;
                    btnEdit.Enabled = false;
                    btnDelete.Enabled = false;
                    btnPrintWOLine.Enabled = false;
                    ConfigGrid(false);
                    dtmTransDate.Focus();
                    dgrdData.AllowDelete = true;
                    btnBOM.Enabled = false;
                    btnRouting.Enabled = false;
                    btnCost.Enabled = false;
                    btnSaleOrderCode.Enabled = true;
                    btnFGoodsCode.Enabled = true;
                    txtSaleOrderCode.Enabled = true;
                    txtFGoodsCode.Enabled = true;

                    txtMasterLocation.Enabled = true;
                    btnSearchMasLoc.Enabled = true;
                    btnProductionLine.Enabled = true;
                    txtProductionLine.Enabled = true;
                    btnDCPCycle.Enabled = true;
                    txtDCPCycle.Enabled = true;
                    btnPrint.Enabled = false;
                    break;
                case EnumAction.Edit:
                    btnEdit.Enabled = false;
                    btnAdd.Enabled = false;
                    dtmTransDate.Enabled = true;
                    txtDescription.Enabled = true;
                    btnSearchWO.Enabled = false;
                    btnSave.Enabled = true;
                    btnPrintWOLine.Enabled = false;
                    ConfigGrid(false);
                    dtmTransDate.Focus();
                    dgrdData.AllowDelete = true;
                    btnBOM.Enabled = false;
                    btnRouting.Enabled = false;
                    btnCost.Enabled = false;
                    btnDelete.Enabled = false;
                    btnSaleOrderCode.Enabled = true;
                    btnFGoodsCode.Enabled = true;
                    txtSaleOrderCode.Enabled = true;
                    txtFGoodsCode.Enabled = true;

                    txtMasterLocation.Enabled = false;
                    btnSearchMasLoc.Enabled = false;
                    btnProductionLine.Enabled = true;
                    txtProductionLine.Enabled = true;
                    btnDCPCycle.Enabled = true;
                    txtDCPCycle.Enabled = true;
                    btnPrint.Enabled = false;
                    break;
            }
        }

        /// <summary>
        /// Clear all data in form to add new record
        /// </summary>
        private void ResetForm()
        {
            voWorkOrderMaster = new PRO_WorkOrderMaster();
            chkFinance.Checked = false;
            chkManufacture.Checked = false;
            txtMasterLocation.Text = string.Empty;
            txtWONo.Text = string.Empty;
            txtProductionLine.Text = string.Empty;
            txtProductionLine.Tag = null;
            txtDCPCycle.Text = string.Empty;
            txtDCPCycle.Tag = null;
            txtDCPDescription.Text = string.Empty;
            txtDescription.Text = string.Empty;
            dtmTransDate.Focus();
            dtmDate.CustomFormat = Constants.DATETIME_FORMAT_HOUR;
            dtmDate.Value = new UtilsBO().GetDBDate();
            txtSaleOrderCode.Text = string.Empty;
            lblSaleOrderCode.Tag = 0;
            txtFGoodsCode.Text = string.Empty;
            lblFGoodsCode.Tag = 0;
        }

        /// <summary>
        /// Get data of WOMaster into voWorkOrderMaster
        /// <author>
        /// Do Manh Tuan
        /// Friday, Jun - 3 - 2005
        /// </author>
        /// <addition>
        /// Addition function not in Design
        /// </addition>
        /// </summary>
        private void GetDataOfWorkOrderMaster()
        {
            voWorkOrderMaster.CCNID = int.Parse(cboCCN.SelectedValue.ToString());
            voWorkOrderMaster.MasterLocationID = voMasLoc.MasterLocationID;
            if (txtProductionLine.Text != string.Empty)
                voWorkOrderMaster.ProductionLineID = int.Parse(txtProductionLine.Tag.ToString());
            else
                voWorkOrderMaster.ProductionLineID = null;
            voWorkOrderMaster.WorkOrderNo = txtWONo.Text.Trim();
            voWorkOrderMaster.TransDate = DateTime.Parse(dtmTransDate.Value.ToString());
            voWorkOrderMaster.Description = txtDescription.Text.Trim();
            // dcp cycle information
            if (txtDCPCycle.Text != string.Empty)
                voWorkOrderMaster.DCOptionMasterID = Convert.ToInt32(txtDCPCycle.Tag);
            else
                voWorkOrderMaster.DCOptionMasterID = null;
        }

        /// <summary>
        /// - Get SaleOrderMasterID from return value of OpenSearchForm method (DataRow)
        /// - Get SO_SaleOrderMasterVO object by SaleOrderMasterID
        /// - Fill value to following columns of grid: 
        /// 	+ Sale Order Master = SO_SaleOrderMasterVO.Code
        /// 	+ SaleOrderMasterID = SO_SaleOrderMasterVO.SaleOrderMasterID
        /// - Clear sale order line data: Sale Order Line, SaleOrderDetailID columns
        /// </summary>
        private void FillSaleOrderData(DataRow pdrowData)
        {
            txtSaleOrderCode.Text = pdrowData[SALE_ORDER_CODE].ToString();
            try
            {
                lblSaleOrderCode.Tag = int.Parse(pdrowData[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD].ToString());
            }
            catch
            {
                lblSaleOrderCode.Tag = 0;
            }
            txtFGoodsCode.Text = pdrowData[SO_SaleOrderDetailTable.FGOODSCODE_FLD].ToString();
            try
            {
                lblFGoodsCode.Tag = int.Parse(pdrowData[SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD].ToString());
            }
            catch
            {
                lblFGoodsCode.Tag = 0;
            }
            foreach (DataRow objRow in dstGridData.Tables[0].Rows)
            {
                objRow[SO_SaleOrderDetailTable.FGOODSCODE_FLD] = pdrowData[SO_SaleOrderDetailTable.FGOODSCODE_FLD].ToString();
                objRow[SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD] = pdrowData[SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD].ToString();

                objRow[SALE_ORDER_CODE] = pdrowData[SALE_ORDER_CODE].ToString();
                objRow[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD] = pdrowData[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD].ToString();
            }
        }
        /// <summary>
        /// - Get SaleOrderDetailID from return value of OpenSearchForm method (DataRow)
        /// - Get SO_SaleOrderDetailVO object by SaleOrderDetailID
        /// - Fill value to following columns of grid: 
        /// 	+ Sale Order Line = SO_SaleOrderDetailVO.SaleOrderLine
        /// 	+ SaleOrderDetailID = SO_SaleOrderDetailVO.SaleOrderDetailID
        /// </summary>
        private void FillSOLineData(DataRow pdrowData)
        {
            txtFGoodsCode.Text = pdrowData[SO_SaleOrderDetailTable.FGOODSCODE_FLD].ToString();
            lblFGoodsCode.Tag = int.Parse(pdrowData[PRO_WorkOrderDetailTable.SALEORDERDETAILID_FLD].ToString());
            foreach (DataRow drow in dstGridData.Tables[0].Rows)
            {
                drow[SO_SaleOrderDetailTable.FGOODSCODE_FLD] = pdrowData[SO_SaleOrderDetailTable.FGOODSCODE_FLD].ToString();
                drow[PRO_WorkOrderDetailTable.SALEORDERDETAILID_FLD] = pdrowData[PRO_WorkOrderDetailTable.SALEORDERDETAILID_FLD].ToString();
            }
        }
        /// <summary>
        /// - get PRO_WorkOrderMasterVO from ID
        /// - fill data to TransDate, MasterLocation, Work Order No, Description
        /// - get all work order line by work order master id
        /// - bind data to grid.
        /// </summary>
        private void FillWOData(int pintWOMasterID)
        {
            voWorkOrderMaster = boWorkOrder.GetWorkOrderDetail(pintWOMasterID);
            txtDescription.Text = voWorkOrderMaster.Description;
            txtWONo.Text = voWorkOrderMaster.WorkOrderNo;
            dtmTransDate.Value = voWorkOrderMaster.TransDate;
            if (voWorkOrderMaster.ProductionLineID != 0)
            {
                int iProductLine = voWorkOrderMaster.ProductionLineID ?? 0;
                txtProductionLine.Text = boWorkOrder.GetProductionLineByID(iProductLine);
                txtProductionLine.Tag = voWorkOrderMaster.ProductionLineID;
            }
            else
            {
                txtProductionLine.Text = string.Empty;
                txtProductionLine.Tag = null;
            }
            if (voWorkOrderMaster.DCOptionMasterID > 0)
            {
                DataRowView drvProLine = FormControlComponents.OpenSearchForm(PRO_DCOptionMasterTable.TABLE_NAME, PRO_DCOptionMasterTable.DCOPTIONMASTERID_FLD, voWorkOrderMaster.DCOptionMasterID.ToString(), null, false);
                if (drvProLine != null)
                {
                    txtDCPCycle.Text = drvProLine[PRO_DCOptionMasterTable.CYCLE_FLD].ToString();
                    txtDCPCycle.Tag = drvProLine[PRO_DCOptionMasterTable.DCOPTIONMASTERID_FLD];
                    txtDCPDescription.Text = drvProLine[PRO_DCOptionMasterTable.DESCRIPTION_FLD].ToString();
                }
            }
            else
            {
                txtDCPCycle.Text = string.Empty;
                txtDCPCycle.Tag = null;
                txtDCPDescription.Text = string.Empty;
            }
            chkFinance.Checked = false;
            chkManufacture.Checked = false;
            BindDataToGrid();
            if (CheckWOLines(WOLineStatus.MfgClose))
            {
                chkManufacture.Checked = true;
            }
            else
            {
                if (CheckWOLines(WOLineStatus.FinClose))
                {
                    chkFinance.Checked = true;
                }
            }
        }


        private void FillWOData(DataRow pdrowData)
        {
            voWorkOrderMaster.WorkOrderMasterID = int.Parse(pdrowData[PRO_WorkOrderMasterTable.WORKORDERMASTERID_FLD].ToString());
            voWorkOrderMaster.MasterLocationID = int.Parse(pdrowData[PRO_WorkOrderMasterTable.MASTERLOCATIONID_FLD].ToString());
            txtDescription.Text = pdrowData[PRO_WorkOrderMasterTable.DESCRIPTION_FLD].ToString().Trim();
            txtWONo.Text = pdrowData[PRO_WorkOrderMasterTable.WORKORDERNO_FLD].ToString();
            dtmTransDate.Value = pdrowData[PRO_WorkOrderMasterTable.TRANSDATE_FLD].ToString();

            #region Add by CanhNv: Fill Info detail to master
            if (pdrowData[PRO_WorkOrderDetailTable.SALEORDERDETAILID_FLD] != DBNull.Value &&
                pdrowData[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD] != DBNull.Value)
            {
                try
                {
                    lblSaleOrderCode.Tag = int.Parse(pdrowData[PRO_WorkOrderDetailTable.SALEORDERMASTERID_FLD].ToString());
                    txtSaleOrderCode.Text = pdrowData[SALE_ORDER_CODE].ToString();
                }
                catch
                {
                    lblSaleOrderCode.Tag = 0;
                    txtSaleOrderCode.Text = string.Empty;
                }
                try
                {
                    lblFGoodsCode.Tag = int.Parse(pdrowData[SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD].ToString());
                    txtFGoodsCode.Text = pdrowData[SO_SaleOrderDetailTable.FGOODSCODE_FLD].ToString();
                }
                catch
                {
                    lblFGoodsCode.Tag = 0;
                    txtFGoodsCode.Text = string.Empty;
                }
            }
            else
            {
                lblSaleOrderCode.Tag = 0;
                txtSaleOrderCode.Text = string.Empty;
                lblFGoodsCode.Tag = 0;
                txtFGoodsCode.Text = string.Empty;
            }
            #endregion End CanhNv.

            BindDataToGrid();
            SwitchFormMode();
            chkFinance.Checked = false;
            chkManufacture.Checked = false;
            if (CheckWOLines(WOLineStatus.MfgClose))
            {
                chkManufacture.Checked = true;
            }
            else
            {
                if (CheckWOLines(WOLineStatus.FinClose))
                {
                    chkFinance.Checked = true;
                }
            }
            strLastValidPro = txtProductionLine.Text;
        }
        /// <summary>
        /// - store all columns header caption for localize purpose
        /// - bind dataset to grid data source
        /// - restore all columns header caption
        /// </summary>
        /// <author>
        /// Do Manh Tuan
        /// 09-06-2005
        /// </author>
        private void BindDataToGrid()
        {
            dstGridData = boWorkOrder.GetWODetailByMaster(voWorkOrderMaster.WorkOrderMasterID);
            dgrdData.DataSource = dstGridData.Tables[0];

            //restore the layout of grid
            FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayOut);

            //enable and disbale button
            btnAdd.Enabled = false;
        }

        #region Grid Events

        /// <summary>
        /// When user move to another row of gird, we need to check
        /// status of this line
        /// - if status is un-release then allow user to change information
        /// - if status is released/mfg close/finance close then not allow user to chagne information
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgrdData_RowColChange(object sender, RowColChangeEventArgs e)
        {

        }

        /// <summary>
        /// before delete selected row, we need to check status of work order line
        /// if Status = unrelease then delete
        /// else cancel
        /// </summary>
        /// <param name="sender">TrueDBGrid</param>
        /// <param name="e">CancelEvent</param>
        private void dgrdData_BeforeDelete(object sender, CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_BeforeDelete()";
            try
            {
                //if WO's status is UnRealease
                if (dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString() != string.Empty)
                {
                    if ((int)WOLineStatus.Unreleased != int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STATUS_FLD].ToString()))
                    {
                        //throw error message
                        PCSMessageBox.Show(ErrorCode.MESSAGE_WO_CANNOT_DELWOLINE, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                    else
                    {
                        ArlWOLineID.Add(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString());
                    }
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// - store value of cell before edit in order to restore if has error
        /// - we need to check status of current work order line
        /// if Status = unrelease then allow user to edit
        /// else lock column and cancel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgrdData_BeforeColEdit(object sender, BeforeColEditEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_BeforeColEdit()";
            try
            {
                if (dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString() != string.Empty)
                {
                    if (dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STATUS_FLD].ToString() != string.Empty)
                    {
                        if ((int)WOLineStatus.Unreleased != int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STATUS_FLD].ToString()))
                        {
                            e.Cancel = true;
                        }
                    }
                    if (e.Column.DataColumn.DataField == ITM_ProductTable.CODE_FLD
                        || e.Column.DataColumn.DataField == ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD)
                    {
                        e.Cancel = true;
                    }
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// after user end update data in cell, 
        /// we need to update related data column(s) if any.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgrdData_AfterColUpdate(object sender, ColEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_AfterColUpdate()";
            try
            {
                if (e.Column.DataColumn.DataField == ITM_ProductTable.CODE_FLD ||
                    e.Column.DataColumn.DataField == ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD)
                {
                    if ((e.Column.DataColumn.Tag == null) || (e.Column.DataColumn.Value.ToString() == string.Empty))
                    {
                        int row = dgrdData.Row;

                        //HACK: added by Tuan TQ. 23 May, 2006. Set value to Category column
                        dgrdData[row, ITM_CategoryTable.TABLE_NAME + ITM_CategoryTable.CODE_FLD] = string.Empty;
                        //End hack

                        dgrdData[row, PRO_WorkOrderDetailTable.LINE_FLD] = string.Empty;
                        dgrdData[row, ITM_ProductTable.CODE_FLD] = string.Empty;
                        dgrdData[row, ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD] = string.Empty;
                        dgrdData[row, ITM_ProductTable.REVISION_FLD] = string.Empty;
                        dgrdData[row, PRO_WorkOrderDetailTable.PRODUCTID_FLD] = null;
                        dgrdData[row, PRO_WorkOrderDetailTable.STOCKUMID_FLD] = null;
                        dgrdData[row, PRO_WorkOrderDetailTable.AGC_FLD] = null;
                        dgrdData[row, PRO_WorkOrderDetailTable.ESTCST_FLD] = string.Empty;
                        dgrdData[row, PRO_WorkOrderDetailTable.AGC_FLD] = null;
                        dgrdData[row, ITM_ProductTable.COSTMETHOD_FLD] = string.Empty;
                        dgrdData[row, AGC_CODE] = string.Empty;
                        dgrdData[row, UM] = string.Empty;
                        dgrdData[row, STATUS_STRING] = string.Empty;
                        dgrdData[row, PRO_WorkOrderDetailTable.STATUS_FLD] = string.Empty;
                        dgrdData[row, PRO_WorkOrderDetailTable.WORKORDERMASTERID_FLD] = null;
                        dgrdData[row, PRO_WorkOrderDetailTable.SALEORDERDETAILID_FLD] = null;
                    }
                    else
                        FillItemData((DataRow)e.Column.DataColumn.Tag);
                }
                else if (e.Column.DataColumn.DataField == PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD)
                {
                    if ((e.Column.DataColumn.Tag == null) || (e.Column.DataColumn.Value.ToString() == string.Empty))
                    {
                        int row = dgrdData.Row;

                        dgrdData[row, PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD] = string.Empty;
                        dgrdData[row, PRO_WorkOrderDetailTable.PRODUCTIONLINEID_FLD] = null;
                    }
                    else
                        FillProductionLine((DataRow)e.Column.DataColumn.Tag);
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// - get column name and opean search form for associated column
        /// - fill data to grid after user select a record
        /// </summary>
        /// <author>
        /// Do Manh Tuan
        /// Friday, Jun - 3 - 2005
        /// </author>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgrdData_ButtonClick(object sender, ColEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_ButtonClick()";
            try
            {
                DataRowView drwResult = null;
                Hashtable htbCondition = new Hashtable();
                if (!btnSave.Enabled) return;
                if (dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD] != null
                    && dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString() != string.Empty)
                {
                    if ((int)WOLineStatus.Unreleased != int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STATUS_FLD].ToString()))
                        return;
                }
                if (dgrdData.Columns[dgrdData.Col].DataField == PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD)
                {
                    if (dgrdData.AddNewMode == AddNewModeEnum.AddNewCurrent)
                        drwResult = FormControlComponents.OpenSearchForm(PRO_ProductionLineTable.TABLE_NAME, PRO_ProductionLineTable.CODE_FLD, dgrdData[dgrdData.Row, PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD].ToString(), null, true);
                    else
                        drwResult = FormControlComponents.OpenSearchForm(PRO_ProductionLineTable.TABLE_NAME, PRO_ProductionLineTable.CODE_FLD, dgrdData.Columns[PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD].Text.Trim(), null, true);
                    if (drwResult != null)
                        FillProductionLine(drwResult.Row);
                }
                if ((dgrdData.Col == dgrdData.Columns.IndexOf(dgrdData.Columns[ITM_ProductTable.CODE_FLD])) && ((dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString() == string.Empty)))
                {
                    //open the search form to select Product
                    htbCondition = new Hashtable();
                    if (cboCCN.SelectedValue != null)
                    {
                        htbCondition.Add(ITM_ProductTable.MAKEITEM_FLD, 1);
                        htbCondition.Add(ITM_ProductTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                    }
                    else
                        htbCondition.Add(ITM_ProductTable.CCNID_FLD, 0);
                    if (dgrdData.AddNewMode == AddNewModeEnum.AddNewCurrent)
                        drwResult = FormControlComponents.OpenSearchForm(ITM_ProductTable.TABLE_NAME, ITM_ProductTable.CODE_FLD, dgrdData[dgrdData.Row, ITM_ProductTable.CODE_FLD].ToString(), htbCondition, true);
                    else
                        drwResult = FormControlComponents.OpenSearchForm(ITM_ProductTable.TABLE_NAME, ITM_ProductTable.CODE_FLD, dgrdData.Columns[ITM_ProductTable.CODE_FLD].Text.Trim(), htbCondition, true);
                    if (drwResult != null)
                        FillItemData(drwResult.Row);
                }

                if ((dgrdData.Col == dgrdData.Columns.IndexOf(dgrdData.Columns[ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD])) && ((dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString() == string.Empty)))
                {
                    //open the search form to select Product
                    htbCondition = new Hashtable();
                    if (cboCCN.SelectedValue != null)
                    {
                        htbCondition.Add(ITM_ProductTable.MAKEITEM_FLD, 1);
                        htbCondition.Add(ITM_ProductTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                    }
                    else
                    {
                        htbCondition.Add(ITM_ProductTable.CCNID_FLD, 0);
                    }
                    if (dgrdData.AddNewMode == AddNewModeEnum.AddNewCurrent)
                        drwResult = FormControlComponents.OpenSearchForm(ITM_ProductTable.TABLE_NAME, ITM_ProductTable.DESCRIPTION_FLD, dgrdData[dgrdData.Row, ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD].ToString(), htbCondition, true);
                    else
                        drwResult = FormControlComponents.OpenSearchForm(ITM_ProductTable.TABLE_NAME, ITM_ProductTable.DESCRIPTION_FLD, dgrdData.Columns[ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD].Text.Trim(), htbCondition, true);
                    if (drwResult != null)
                        FillItemData(drwResult.Row);
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// after delete a row on grid, we need to update line cell
        /// </summary>
        /// <author>
        /// Do Manh Tuan
        /// 08-06-2005
        /// </author>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgrdData_AfterDelete(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_AfterDelete()";
            try
            {
                for (int i = 0; i < dgrdData.RowCount; i++)
                {
                    if (dgrdData[i, PRO_WorkOrderDetailTable.PRODUCTID_FLD].ToString() != string.Empty)
                    {
                        dgrdData[i, PRO_WorkOrderDetailTable.LINE_FLD] = i + 1;
                    }
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void dgrdData_Enter(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_Enter()";
            try
            {
                if (dgrdData.Col == 0)
                {
                    dgrdData.Row = 0;
                    dgrdData.Col = dgrdData.Splits[0].DisplayColumns.IndexOf(dgrdData.Splits[0].DisplayColumns[ITM_ProductTable.CODE_FLD]);
                    dgrdData.Focus();
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        #endregion

        #region Change backcolor when focus or lost focus
        private void OnEnterControl(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ". OnEnterControl()";
            try
            {
                FormControlComponents.OnEnterControl(sender, e);
            }
            catch (Exception ex)
            {
                // displays the error message.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                // log message.
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void OnLeaveControl(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ". OnLeaveControl()";
            try
            {
                FormControlComponents.OnLeaveControl(sender, e);
            }
            catch (Exception ex)
            {
                // displays the error message.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                // log message.
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        #endregion

        /// <summary>
        /// Reset all control if Master change
        /// </summary>
        private void ResetFormIfMasLocChanged()
        {
            txtWONo.Text = string.Empty;
            txtDescription.Text = string.Empty;
            txtProductionLine.Text = string.Empty;
            txtProductionLine.Tag = null;
            dtmTransDate.Value = DBNull.Value;
            CreateDataSet();
            dgrdData.DataSource = dstGridData.Tables[0];
            FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayOut);
            FormMode = EnumAction.Default;
            SwitchFormMode();
        }


        /// <summary>
        /// Reset all control if WO changed
        /// </summary>
        private void ResetFormIfWOChanged()
        {
            txtProductionLine.Text = string.Empty;
            txtProductionLine.Tag = null;
            txtDescription.Text = string.Empty;
            txtDCPCycle.Text = string.Empty;
            txtDCPCycle.Tag = null;
            txtDCPDescription.Text = string.Empty;
            dtmTransDate.Value = DBNull.Value;
            CreateDataSet();
            dgrdData.DataSource = dstGridData.Tables[0];
            FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayOut);
            FormMode = EnumAction.Default;
            SwitchFormMode();
        }
        /// <summary>
        /// Leave event:
        ///		Open the search form if it's necessary
        /// </summary>
        /// <author>
        /// Do Manh Tuan
        /// Thursday, Jun - 2 - 2005
        /// </author>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtWONo_Leave(object sender, System.EventArgs e)
        {

        }

        /// <summary>
        /// Check data on grid
        /// </summary>
        /// <param name="sender"></param>
        /// <author>
        /// Do Manh Tuan
        /// 07 - 06 - 2005
        /// </author>
        /// <param name="e"></param>
        private void dgrdData_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_BeforeColUpdate()";
            try
            {
                if (e.Column.DataColumn.Value.ToString() == string.Empty) return;
                Hashtable htbCriteria = new Hashtable();
                DataRowView drwResult = null;
                switch (e.Column.DataColumn.DataField)
                {
                    case ITM_ProductTable.CODE_FLD:
                        # region open Product search form
                        if (dgrdData.Columns[e.Column.DataColumn.DataField].Text.Trim() != string.Empty)
                        {
                            if (cboCCN.SelectedIndex >= 0)
                            {
                                htbCriteria.Add(MST_CCNTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                                htbCriteria.Add(ITM_ProductTable.MAKEITEM_FLD, 1);
                            }
                            else
                                htbCriteria.Add(MST_CCNTable.CCNID_FLD, 0);
                            drwResult = FormControlComponents.OpenSearchForm(ITM_ProductTable.TABLE_NAME, ITM_ProductTable.CODE_FLD, dgrdData.Columns[e.Column.DataColumn.DataField].Text.Trim(), htbCriteria, false);
                            if (drwResult != null)
                                e.Column.DataColumn.Tag = drwResult.Row;
                            else
                                e.Cancel = true;
                        }
                        #endregion
                        break;
                    case ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD:
                        # region open Product search form
                        if (dgrdData.Columns[e.Column.DataColumn.DataField].Text.Trim() != string.Empty)
                        {
                            if (cboCCN.SelectedIndex >= 0)
                            {
                                htbCriteria.Add(MST_CCNTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                                htbCriteria.Add(ITM_ProductTable.MAKEITEM_FLD, 1);
                            }
                            else
                                htbCriteria.Add(MST_CCNTable.CCNID_FLD, 0);
                            drwResult = FormControlComponents.OpenSearchForm(ITM_ProductTable.TABLE_NAME, ITM_ProductTable.DESCRIPTION_FLD, dgrdData.Columns[e.Column.DataColumn.DataField].Text.Trim(), htbCriteria, false);
                            if (drwResult != null)
                                e.Column.DataColumn.Tag = drwResult.Row;
                            else
                                e.Cancel = true;
                        }
                        #endregion
                        break;
                    case PRO_ProductionLineTable.TABLE_NAME + PRO_ProductionLineTable.CODE_FLD:
                        # region open Product search form
                        if (dgrdData.Columns[e.Column.DataColumn.DataField].Text.Trim() != string.Empty)
                        {
                            drwResult = FormControlComponents.OpenSearchForm(PRO_ProductionLineTable.TABLE_NAME, PRO_ProductionLineTable.CODE_FLD, dgrdData.Columns[e.Column.DataColumn.DataField].Text.Trim(), null, false);
                            if (drwResult != null)
                                e.Column.DataColumn.Tag = drwResult.Row;
                            else
                                e.Cancel = true;
                        }
                        #endregion
                        break;
                }

                //check quantity
                if (dgrdData.Splits[0].DisplayColumns[dgrdData.Col].DataColumn.DataField == PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD)
                {
                    try
                    {
                        float fQuantity = float.Parse(dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD].DataColumn.Value.ToString().Trim());
                        if (fQuantity < 0.0)
                        {
                            PCSMessageBox.Show(ErrorCode.MESSAGE_WO_ORDERQUANTITY, MessageBoxIcon.Error);
                            e.Cancel = true;
                        }
                    }
                    catch
                    {
                        //cancel update and throw PCSException
                        e.Cancel = true;
                        PCSMessageBox.Show(ErrorCode.MESSAGE_WO_ORDERQUANTITY, MessageBoxIcon.Error);
                    }
                }

                //check start date
                if (e.Column.DataColumn.DataField == PRO_WorkOrderDetailTable.STARTDATE_FLD)
                {
                    try
                    {
                        if (e.Column.DataColumn.Value.ToString() != string.Empty)
                        {
                            DateTime dtmStart = DateTime.Parse(dtmDate.Value.ToString());
                            if (dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.DUEDATE_FLD].ToString() != string.Empty)
                            {
                                DateTime dtmDue = DateTime.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.DUEDATE_FLD].ToString());
                                if (dtmDue < dtmStart)
                                {
                                    PCSMessageBox.Show(ErrorCode.MESSAGE_WO_STARTDATE_DUEDATE, MessageBoxIcon.Error);
                                    e.Cancel = true;
                                }
                            }
                        }
                    }
                    catch
                    {
                        PCSMessageBox.Show(ErrorCode.MESSAGE_INVALID_DATETIME, MessageBoxIcon.Error);
                        e.Cancel = true;
                    }
                }

                //check due date
                if (e.Column.DataColumn.DataField == PRO_WorkOrderDetailTable.DUEDATE_FLD)
                {
                    try
                    {
                        if (e.Column.DataColumn.Value.ToString() != string.Empty)
                        {
                            DateTime dtmDue = DateTime.Parse(dtmDate.Value.ToString());
                            if (dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STARTDATE_FLD].ToString() != string.Empty)
                            {
                                DateTime dtmStart = DateTime.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STARTDATE_FLD].ToString());
                                if (dtmDue < dtmStart)
                                {
                                    PCSMessageBox.Show(ErrorCode.MESSAGE_WO_STARTDATE_DUEDATE, MessageBoxIcon.Error);
                                    e.Cancel = true;
                                }
                            }
                        }
                    }
                    catch
                    {
                        PCSMessageBox.Show(ErrorCode.MESSAGE_INVALID_DATETIME, MessageBoxIcon.Error);
                        e.Cancel = true;
                    }
                }
                //check group quantity
                if (dgrdData.Splits[0].DisplayColumns[dgrdData.Col].DataColumn.DataField == PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD)
                {
                    if (dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD].DataColumn.Value.ToString().Trim().Length != 0)
                    {
                        try
                        {
                            float fQuantity = float.Parse(dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.GROUPQUANTITY_FLD].DataColumn.Value.ToString().Trim());
                            if (fQuantity < 0.0)
                            {
                                PCSMessageBox.Show(ErrorCode.MESSAGE_WO_ORDERQUANTITY, MessageBoxIcon.Error);
                                e.Cancel = true;
                            }
                        }
                        catch
                        {
                            //cancel update and throw PCSException
                            e.Cancel = true;
                            PCSMessageBox.Show(ErrorCode.MESSAGE_WO_ORDERQUANTITY, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// txtDescription Leave event:
        ///		Set focus to Part Number column in grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtDescription_Leave(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtDescription_Leave()";
            try
            {
                OnLeaveControl(sender, e);
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// Closing event
        /// </summary>
        /// <author>
        /// Do Manh Tuan
        /// 09-06-2005
        /// </author>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WorkOrder_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".WorkOrder_Closing()";
            try
            {
                if (FormMode != EnumAction.Default)
                {
                    DialogResult confirmDialog = PCSMessageBox.Show(ErrorCode.MESSAGE_QUESTION_STORE_INTO_DATABASE, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    switch (confirmDialog)
                    {
                        case DialogResult.Yes:
                            //Save before exit
                            btnSave_Click(btnSave, new EventArgs());
                            if (blnHasError)
                            {
                                e.Cancel = true;
                            }
                            break;
                        case DialogResult.No:
                            break;
                        case DialogResult.Cancel:
                            e.Cancel = true;
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// Change column focus in the grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dtmDate_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dtmDate_KeyDown()";
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    dgrdData.Col = dgrdData.Col + 1;
                    dgrdData.Focus();
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        /// <summary>
        /// Get fully datetime
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dtmDate_DropDownClosed(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".dtmDate_DropDownClosed()";
            try
            {
                if (dtmDate.Text != string.Empty)
                {
                    DateTime dtmValue = new DateTime(DateTime.Parse(dtmDate.Value.ToString()).Year, DateTime.Parse(dtmDate.Value.ToString()).Month, DateTime.Parse(dtmDate.Value.ToString()).Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                    dtmDate.Value = dtmValue;
                }
                else
                {
                    dgrdData[dgrdData.Row, dgrdData.Col] = DBNull.Value;
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void txtMasterLocation_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtMasterLocation_KeyDown()";
            try
            {
                if ((e.KeyCode == Keys.F4) && (btnSearchMasLoc.Enabled))
                {
                    btnSearchMasLoc_Click(sender, e);
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void txtWONo_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtWONo_KeyDown()";
            try
            {
                if ((e.KeyCode == Keys.F4) && (btnSearchWO.Enabled))
                {
                    btnSearchWO_Click(sender, e);
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }


        private void dtmDate_Enter(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".dtmDate_Enter()", FIRSTDATE = "01-01-0001";
            const int LENGTH = 10;
            try
            {
                if ((dtmDate.Text == string.Empty) || (dtmDate.Text.Substring(0, LENGTH) == FIRSTDATE))
                {
                    dtmDate.Value = new UtilsBO().GetDBDate();
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void dtmTransDate_DropDownClosed(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".dtmTransDate_DropDownClosed()";
            try
            {
                if (dtmTransDate.Text == string.Empty)
                {
                    dtmTransDate.Value = DBNull.Value;
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void txtMasterLocation_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtMasterLocation_Leave()";
            try
            {
                OnLeaveControl(sender, e);
                if (txtMasterLocation.Text == string.Empty)
                {
                    if (voWorkOrderMaster.WorkOrderMasterID != 0)
                    {
                        voMasLoc.MasterLocationID = 0;
                        ResetFormIfMasLocChanged();
                    }
                    return;
                }
                if (!txtMasterLocation.Modified) return;
                Hashtable htbCriteria = new Hashtable();
                if (cboCCN.SelectedIndex != -1)
                {
                    htbCriteria.Add(SO_SaleOrderMasterTable.CCNID_FLD, cboCCN.SelectedValue);
                }
                else
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_RGA_CCN, MessageBoxIcon.Warning);
                    e.Cancel = true;
                    return;
                }
                DataRowView drwResult = FormControlComponents.OpenSearchForm(MST_MasterLocationTable.TABLE_NAME, MST_MasterLocationTable.CODE_FLD, txtMasterLocation.Text.Trim(), htbCriteria, false);
                if (drwResult != null)
                {
                    txtMasterLocation.Text = drwResult[MST_MasterLocationTable.CODE_FLD].ToString();
                    voMasLoc.MasterLocationID = int.Parse(drwResult[MST_MasterLocationTable.MASTERLOCATIONID_FLD].ToString());
                    if ((voMasLoc.MasterLocationID != voWorkOrderMaster.MasterLocationID) && (voWorkOrderMaster.MasterLocationID != 0))
                    {
                        ResetFormIfMasLocChanged();
                    }
                }
                else
                    e.Cancel = true;
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void txtWONo_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtWONo_Validating()";
            try
            {
                if (mFormMode == EnumAction.Edit) return;
                if (mFormMode != EnumAction.Add)
                {
                    if (txtWONo.Text == string.Empty)
                    {
                        if (voWorkOrderMaster.WorkOrderMasterID != 0)
                        {
                            voWorkOrderMaster.WorkOrderMasterID = 0;
                            ResetFormIfWOChanged();
                        }
                        return;
                    }
                    if (!txtWONo.Modified) return;
                    Hashtable htbCondition = new Hashtable();
                    if (txtMasterLocation.Text.Trim() != string.Empty)
                    {
                        htbCondition.Add(PRO_WorkOrderMasterTable.CCNID_FLD, cboCCN.SelectedValue);
                        htbCondition.Add(PRO_WorkOrderMasterTable.MASTERLOCATIONID_FLD, voMasLoc.MasterLocationID);
                    }
                    else
                    {
                        PCSMessageBox.Show(ErrorCode.MESSAGE_RGA_MASTERLOCATION, MessageBoxIcon.Warning);
                        e.Cancel = true;
                        return;
                    }
                    //					DataRowView drwResult = FormControlComponents.OpenSearchForm(PRO_WorkOrderMasterTable.TABLE_NAME, PRO_WorkOrderMasterTable.WORKORDERNO_FLD, txtWONo.Text.Trim(), htbCondition, false);
                    DataRowView drwResult = FormControlComponents.OpenSearchForm("v_PROWorkOrderMasterJoinSaleOrderDetail", PRO_WorkOrderMasterTable.WORKORDERNO_FLD, txtWONo.Text, htbCondition, false);
                    if (drwResult != null)
                    {
                        txtWONo.Text = drwResult[PRO_WorkOrderMasterTable.WORKORDERNO_FLD].ToString();
                        txtDescription.Text = drwResult[PRO_WorkOrderMasterTable.DESCRIPTION_FLD].ToString();
                        voWorkOrderMaster.WorkOrderMasterID = int.Parse(drwResult[PRO_WorkOrderMasterTable.WORKORDERMASTERID_FLD].ToString());
                        voWorkOrderMaster.MasterLocationID = int.Parse(drwResult[PRO_WorkOrderMasterTable.MASTERLOCATIONID_FLD].ToString());
                        voWorkOrderMaster.Description = drwResult[PRO_WorkOrderMasterTable.DESCRIPTION_FLD].ToString();
                        FillWOData(drwResult.Row);
                    }
                    else
                        e.Cancel = true;
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }
        /// <summary>
        /// btnProductionLine_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <author>Trada</author>
        /// <date>Wednesday, January 4 2006</date>
        private void btnProductionLine_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnProductionLine_Click()";
            try
            {
                // 28-04-2006 dungla: fix bug 3926 for NganNT 
                // Expected Results: Can't select other Production Line when has at lease one line has release.
                bool blnCanChangePro = CheckWOLines(WOLineStatus.Unreleased);
                if (!blnCanChangePro)
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_CANNOT_CHANGE_PRODUCTION_LINE, MessageBoxIcon.Warning);
                    // restore last valid pro
                    txtProductionLine.Text = strLastValidPro;
                    return;
                }
                // 28-04-2006 dungla: fix bug 3926 for NganNT
                //Call OpenSearchForm for selecting Production Line
                DataRowView drwResult = FormControlComponents.OpenSearchForm(PRO_ProductionLineTable.TABLE_NAME, PRO_ProductionLineTable.CODE_FLD, txtProductionLine.Text.Trim(), null, true);

                //If has Production Line matched searching condition, fill values to form's controls
                if (drwResult != null)
                {
                    txtProductionLine.Text = drwResult[PRO_ProductionLineTable.CODE_FLD].ToString();
                    txtProductionLine.Tag = drwResult[PRO_ProductionLineTable.PRODUCTIONLINEID_FLD];
                    // 17-04-2006 dungla: fix bug 3771 for NganNT: when user change production line, clear the grid
                    if (!strLastValidPro.Equals(txtProductionLine.Text))
                    {
                        ChangeProductionLine();
                        strLastValidPro = txtProductionLine.Text;
                    }
                    // 17-04-2006 dungla: fix bug 3771 for NganNT: when user change production line, clear the grid
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }
        /// <summary>
        /// txtProductionLine_Validating
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <author>Trada</author>
        /// <date>Wednesday, January 4 2006</date>
        private void txtProductionLine_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtProductionLine_Validating()";
            try
            {
                if (strLastValidPro.Equals(txtProductionLine.Text))
                    return;
                // 28-04-2006 dungla: fix bug 3926 for NganNT 
                // Expected Results: Can't select other Production Line when has at lease one line has release.
                bool blnCanChangePro = CheckWOLines(WOLineStatus.Unreleased);
                if (!blnCanChangePro)
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_CANNOT_CHANGE_PRODUCTION_LINE, MessageBoxIcon.Warning);
                    // restore last valid pro
                    txtProductionLine.Text = strLastValidPro;
                    return;
                }
                // 28-04-2006 dungla: fix bug 3926 for NganNT
                if (txtProductionLine.Text == string.Empty)
                {
                    // 17-04-2006 dungla: fix bug 3771 for NganNT: when user change production line, clear the grid
                    ChangeProductionLine();
                    // 17-04-2006 dungla: fix bug 3771 for NganNT: when user change production line, clear the grid
                    txtProductionLine.Tag = null;
                    strLastValidPro = string.Empty;
                    return;
                }
                //Call OpenSearchForm for selecting Production Line
                DataRowView drwResult = FormControlComponents.OpenSearchForm(PRO_ProductionLineTable.TABLE_NAME, PRO_ProductionLineTable.CODE_FLD, txtProductionLine.Text.Trim(), null, false);

                //If has Production Line matched searching condition, fill values to form's controls
                if (drwResult != null)
                {
                    txtProductionLine.Text = drwResult[PRO_ProductionLineTable.CODE_FLD].ToString();
                    txtProductionLine.Tag = drwResult[PRO_ProductionLineTable.PRODUCTIONLINEID_FLD];
                    // 17-04-2006 dungla: fix bug 3771 for NganNT: when user change production line, clear the grid
                    if (!strLastValidPro.Equals(txtProductionLine.Text))
                    {
                        ChangeProductionLine();
                        strLastValidPro = txtProductionLine.Text;
                    }
                    // 17-04-2006 dungla: fix bug 3771 for NganNT: when user change production line, clear the grid
                }
                else
                    e.Cancel = true;
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }
        /// <summary>
        /// txtProductionLine_KeyDown
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <author>Trada</author>
        /// <date>wednesday, January 4 2006</date>
        private void txtProductionLine_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (btnProductionLine.Enabled && e.KeyCode == Keys.F4)
            {
                btnProductionLine_Click(sender, new EventArgs());
            }
        }

        /// <summary>
        /// Show Work Order Report for each month in Work Order Line
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnPrint_Click()";
            const string TIME_FLD = "LineTime";
            const string PART_NUMBER_FLD = "PartsNumber";
            const string PART_NAME_FLD = "PartsName";
            const string MODEL_FLD = "Model";
            const string UNIT_FLD = "Unit";
            const string COL_PREFIX = "D";
            const string DATE_COL = "lblD";
            const string DAY_COL = "lblDayD";
            const string DAY_FORMAT = "00";
            const string MONTH_FORMAT = "MMM";
            const string SEPERATOR = "-";
            const string DIV_PREFIX = "div";
            const string DATA_PREFIX = "Data";
            const string FOOTER_PREFIX = "Ftr";
            const string TOTAL_FLD = "Total";
            const string LABEL_PREFIX = "lbl";
            const string FIELD_PREFIX = "fld";
            const double FIELD_WIDTH = 500;
            try
            {
                // get all months from due date of work order lines
                if (dstGridData != null && dstGridData.Tables.Count > 0)
                {
                    // waiting cursor
                    Cursor = Cursors.WaitCursor;
                    ReportDefinitionFolder = Application.StartupPath + @"\ReportDefinition";
                    if (!File.Exists(ReportDefinitionFolder + @"\" + ReportFileName))
                    {
                        PCSMessageBox.Show(ErrorCode.MESSAGE_REPORT_TEMPLATE_FILE_NOT_FOUND, MessageBoxIcon.Error);
                        return;
                    }
                    DCPReportBO boReport = new DCPReportBO();
                    DataTable dtbWorkingTime = boReport.GetWorkingTime();
                    DataTable dtbOriginal = dstGridData.Tables[0].Copy();
                    ArrayList arrMonths = new ArrayList();
                    ArrayList arrProducts = new ArrayList();
                    int intProductionLineID = 0;
                    try
                    {
                        intProductionLineID = Convert.ToInt32(txtProductionLine.Tag);
                    }
                    catch { }
                    DataTable dtbValidWorkDay = null;
                    if (intProductionLineID > 0)
                        dtbValidWorkDay = boReport.GetWorkingDateFromWCCapacity(intProductionLineID);
                    foreach (DataRow drowData in dtbOriginal.Rows)
                    {
                        DateTime dtmDueDate = DateTime.MinValue;
                        try
                        {
                            dtmDueDate = (DateTime)drowData[PRO_WorkOrderDetailTable.DUEDATE_FLD];
                            dtmDueDate = new DateTime(dtmDueDate.Year, dtmDueDate.Month, 1);
                        }
                        catch { }
                        if (dtmDueDate != DateTime.MinValue && !arrMonths.Contains(dtmDueDate))
                            arrMonths.Add(dtmDueDate);
                        int intProductID = int.Parse(drowData[ITM_ProductTable.PRODUCTID_FLD].ToString());
                        if (!arrProducts.Contains(intProductID))
                            arrProducts.Add(intProductID);
                    }
                    UtilsBO boUtils = new UtilsBO();
                    foreach (DateTime dtmMonth in arrMonths)
                    {
                        ArrayList arrOffDay = null;
                        ArrayList arrHolidays = null;
                        if (intProductionLineID == 0)
                        {
                            arrOffDay = boUtils.GetWorkingDayByYear(dtmMonth.Year);
                            arrHolidays = boUtils.GetHolidaysInYear(dtmMonth.Year);
                        }
                        string strMonthName = dtmMonth.ToString(MONTH_FORMAT);
                        int intDayInMonth = DateTime.DaysInMonth(dtmMonth.Year, dtmMonth.Month);

                        #region Build the report table

                        DataTable dtbReportData = new DataTable(PRO_WorkOrderMasterTable.TABLE_NAME);
                        //dtbReportData.Columns.Add(new DataColumn(PRO_WorkOrderDetailTable.LINE_FLD, typeof(int)));
                        //dtbReportData.Columns.Add(new DataColumn(TIME_FLD, typeof(DateTime)));
                        dtbReportData.Columns.Add(new DataColumn(PART_NUMBER_FLD, typeof(string)));
                        dtbReportData.Columns.Add(new DataColumn(PART_NAME_FLD, typeof(string)));
                        dtbReportData.Columns.Add(new DataColumn(MODEL_FLD, typeof(string)));
                        dtbReportData.Columns.Add(new DataColumn(UNIT_FLD, typeof(string)));
                        for (int i = 1; i <= intDayInMonth; i++)
                        {
                            dtbReportData.Columns.Add(new DataColumn(COL_PREFIX + i.ToString(DAY_FORMAT), typeof(decimal)));
                            dtbReportData.Columns[COL_PREFIX + i.ToString(DAY_FORMAT)].AllowDBNull = true;
                            dtbReportData.Columns[COL_PREFIX + i.ToString(DAY_FORMAT)].DefaultValue = DBNull.Value;
                        }

                        #endregion

                        #region Copy data from original data to Report data

                        foreach (int intProductID in arrProducts)
                        {
                            DataRow drowReport = dtbReportData.NewRow();
                            bool blnHasValue = false;
                            string strPartNumber = string.Empty;
                            string strPartName = string.Empty;
                            string strModel = string.Empty;
                            string strUnit = string.Empty;
                            // sum quantity by logical day (based on shift pattern)
                            for (int i = 1; i <= intDayInMonth; i++)
                            {
                                string strColName = COL_PREFIX + i.ToString(DAY_FORMAT);
                                DateTime dtmCurrentDay = new DateTime(dtmMonth.Year, dtmMonth.Month, i);
                                DateTime dtmStartTime = dtmMonth;
                                DateTime dtmEndTime = dtmMonth;
                                GetStartAndEndTime(dtmCurrentDay, ref dtmStartTime, ref dtmEndTime, dtbWorkingTime);
                                string strExpression = ITM_ProductTable.PRODUCTID_FLD + "='" + intProductID + "' AND "
                                    + PRO_WorkOrderDetailTable.DUEDATE_FLD + " >= '" + dtmStartTime.ToString("G") + "' AND "
                                    + PRO_WorkOrderDetailTable.DUEDATE_FLD + " < '" + dtmEndTime.ToString("G") + "'";
                                DataRow[] drowLines = dtbOriginal.Select(strExpression);
                                decimal decQuantity = 0;
                                if (drowLines.Length > 0)
                                {
                                    try
                                    {
                                        decQuantity += Convert.ToDecimal(dtbOriginal.Compute("SUM(" + PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD + ")", strExpression));
                                    }
                                    catch { }
                                    if (decQuantity != 0)
                                    {
                                        blnHasValue = true;
                                        strPartNumber = drowLines[0][ITM_ProductTable.CODE_FLD].ToString();
                                        strPartName = drowLines[0][ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD].ToString();
                                        strModel = drowLines[0][ITM_ProductTable.REVISION_FLD].ToString();
                                        strUnit = drowLines[0][UM].ToString();
                                    }
                                    drowReport[strColName] = decQuantity;
                                }
                            }
                            if (blnHasValue)
                            {
                                drowReport[PART_NUMBER_FLD] = strPartNumber;
                                drowReport[PART_NAME_FLD] = strPartName;
                                drowReport[MODEL_FLD] = strModel;
                                drowReport[UNIT_FLD] = strUnit;
                                dtbReportData.Rows.Add(drowReport);
                            }
                        }
                        #endregion

                        if (dtbReportData.Rows.Count == 0)
                            continue;

                        #region Rendering Report

                        //ReportBuilder objRB = new ReportBuilder();
                        C1Report rptWorkOrder = new C1Report();
                        try
                        {
                            // TODO: get the report name from mstrReportName
                            string[] arrstrReportInDefinitionFile = rptWorkOrder.GetReportInfo(
                                ReportDefinitionFolder + "\\" + ReportFileName);
                            rptWorkOrder.Load(ReportDefinitionFolder + "\\" + ReportFileName, arrstrReportInDefinitionFile[0]);
                            arrstrReportInDefinitionFile = null;
                        }
                        catch
                        {
                            return;
                        }
                        rptWorkOrder.Layout.PaperSize = PaperKind.A3;
                        string strTotal = string.Empty;

                        #region Refine the heading

                        for (int i = 1; i <= intDayInMonth; i++)
                        {
                            strTotal += "+ " + COL_PREFIX + i.ToString(DAY_FORMAT);
                            string strColumnName = DATE_COL + i.ToString(DAY_FORMAT);
                            string strDOWColName = DAY_COL + i.ToString(DAY_FORMAT);
                            string strColHeading = i + SEPERATOR + strMonthName;
                            DateTime dtmDay = new DateTime(dtmMonth.Year, dtmMonth.Month, i);
                            string strDayOfWeek = dtmDay.DayOfWeek.ToString().Substring(0, 3);
                            // draw heading
                            try
                            {
                                rptWorkOrder.Fields[strColumnName].Text = strColHeading;
                            }
                            catch { }
                            // draw day of week
                            try
                            {
                                rptWorkOrder.Fields[strDOWColName].Text = strDayOfWeek;
                            }
                            catch { }
                            if (intProductionLineID == 0)
                            {
                                if (arrOffDay.Contains(dtmDay.DayOfWeek) || arrHolidays.Contains(dtmDay))
                                {
                                    try
                                    {
                                        if (dtmDay.DayOfWeek == DayOfWeek.Saturday)
                                        {
                                            rptWorkOrder.Fields[strColumnName].ForeColor = Color.Blue;
                                            rptWorkOrder.Fields[strColumnName].BackColor = Color.Yellow;
                                        }
                                        else
                                        {
                                            rptWorkOrder.Fields[strColumnName].ForeColor = Color.Red;
                                            rptWorkOrder.Fields[strColumnName].BackColor = Color.Yellow;
                                        }
                                    }
                                    catch { }
                                    try
                                    {
                                        if (dtmDay.DayOfWeek == DayOfWeek.Saturday)
                                        {
                                            rptWorkOrder.Fields[strDOWColName].ForeColor = Color.Blue;
                                            rptWorkOrder.Fields[strDOWColName].BackColor = Color.Yellow;
                                        }
                                        else
                                        {
                                            rptWorkOrder.Fields[strDOWColName].ForeColor = Color.Red;
                                            rptWorkOrder.Fields[strDOWColName].BackColor = Color.Yellow;
                                        }
                                    }
                                    catch { }
                                }
                            }
                            else
                            {
                                string strExpression = "BeginDate <= '" + dtmDay.ToString("G") + "'"
                                    + " AND EndDate >='" + dtmDay.ToString("G") + "'";
                                DataRow[] drowValidWorkDay = dtbValidWorkDay.Select(strExpression);
                                if (drowValidWorkDay.Length == 0)
                                {
                                    try
                                    {
                                        if (dtmDay.DayOfWeek == DayOfWeek.Saturday)
                                        {
                                            rptWorkOrder.Fields[strColumnName].ForeColor = Color.Blue;
                                            rptWorkOrder.Fields[strColumnName].BackColor = Color.Yellow;
                                        }
                                        else
                                        {
                                            rptWorkOrder.Fields[strColumnName].ForeColor = Color.Red;
                                            rptWorkOrder.Fields[strColumnName].BackColor = Color.Yellow;
                                        }
                                    }
                                    catch { }
                                    try
                                    {
                                        if (dtmDay.DayOfWeek == DayOfWeek.Saturday)
                                        {
                                            rptWorkOrder.Fields[strDOWColName].ForeColor = Color.Blue;
                                            rptWorkOrder.Fields[strDOWColName].BackColor = Color.Yellow;
                                        }
                                        else
                                        {
                                            rptWorkOrder.Fields[strDOWColName].ForeColor = Color.Red;
                                            rptWorkOrder.Fields[strDOWColName].BackColor = Color.Yellow;
                                        }
                                    }
                                    catch { }
                                }
                            }
                        }

                        #endregion

                        #region hide/show the related fields

                        try
                        {
                            rptWorkOrder.Fields[FIELD_PREFIX + TOTAL_FLD].Text = strTotal.Remove(0, 1);
                        }
                        catch { }

                        if (intDayInMonth < 31)
                        {
                            for (int i = intDayInMonth + 1; i <= 31; i++)
                            {
                                string strDateCol = DATE_COL + i.ToString(DAY_FORMAT);
                                string strDayOfWeek = DAY_COL + i.ToString(DAY_FORMAT);
                                string strDiv = DIV_PREFIX + i.ToString(DAY_FORMAT);
                                string strDivDetail = DIV_PREFIX + DATA_PREFIX + i.ToString(DAY_FORMAT);
                                string strDivFtr = DIV_PREFIX + FOOTER_PREFIX + i.ToString(DAY_FORMAT);
                                string strDetail = FIELD_PREFIX + COL_PREFIX + i.ToString(DAY_FORMAT);
                                string strFooter = FIELD_PREFIX + FOOTER_PREFIX + i.ToString(DAY_FORMAT);
                                // hide the label first
                                try
                                {
                                    rptWorkOrder.Fields[strDateCol].Visible = false;
                                }
                                catch { }
                                // hide the day of week
                                try
                                {
                                    rptWorkOrder.Fields[strDayOfWeek].Visible = false;
                                }
                                catch { }
                                // hide the data field
                                try
                                {
                                    rptWorkOrder.Fields[strDetail].Visible = false;
                                }
                                catch { }
                                // hide the footer
                                try
                                {
                                    rptWorkOrder.Fields[strFooter].Visible = false;
                                }
                                catch { }
                                // hide the div
                                try
                                {
                                    rptWorkOrder.Fields[strDiv].Visible = false;
                                    rptWorkOrder.Fields[strDivDetail].Visible = false;
                                    rptWorkOrder.Fields[strDivFtr].Visible = false;
                                }
                                catch { }
                            }
                            try
                            {
                                #region Resize all line

                                //double dWidth = rptReport.Fields["line1"].Width;
                                for (int i = 1; i <= 5; i++)
                                    rptWorkOrder.Fields["line" + i].Width = rptWorkOrder.Fields["line" + i].Width - (31 - intDayInMonth) * FIELD_WIDTH;

                                #endregion

                                #region moving rest of field in report header

                                #region Total columns
                                rptWorkOrder.Fields["lblDayDTotal"].Left = rptWorkOrder.Fields["lblD" + intDayInMonth.ToString("00")].Left + FIELD_WIDTH;
                                rptWorkOrder.Fields["fldTotal"].Left = rptWorkOrder.Fields["lblD" + intDayInMonth.ToString("00")].Left + FIELD_WIDTH;
                                rptWorkOrder.Fields["lblTotal"].Left = rptWorkOrder.Fields["fldTotal"].Left;
                                rptWorkOrder.Fields["fldFtrTotal"].Left = rptWorkOrder.Fields["lblD" + intDayInMonth.ToString("00")].Left + FIELD_WIDTH;
                                rptWorkOrder.Fields["divTotal"].Left = rptWorkOrder.Fields["lblTotal"].Left + FIELD_WIDTH;
                                rptWorkOrder.Fields["divDataTotal"].Left = rptWorkOrder.Fields["lblTotal"].Left + FIELD_WIDTH;
                                rptWorkOrder.Fields["divFtrTotal"].Left = rptWorkOrder.Fields["lblTotal"].Left + FIELD_WIDTH;
                                #endregion

                                #endregion
                            }
                            catch { }
                        }

                        #endregion

                        rptWorkOrder.DataSource.Recordset = dtbReportData;

                        #endregion

                        #region Modify the report layout

                        const string CCN_FLD = "fldParameterCCN";
                        const string MONTH_FLD = "fldMonth";
                        const string YEAR_FLD = "fldYear";
                        const string PRODUCTION_LINE_FLD = "fldProductionLine";
                        const string WORK_ORDER_FLD = "fldParamWO";
                        const string MAS_LOC_FLD = "fldParamMasLoc";
                        const string DESCRIPTION_FLD = "fldDescription";

                        try
                        {
                            rptWorkOrder.Fields[CCN_FLD].Text = cboCCN.SelectedText;
                        }
                        catch { }
                        try
                        {
                            rptWorkOrder.Fields[MONTH_FLD].Text = dtmMonth.ToString("MMM");
                        }
                        catch { }
                        try
                        {
                            rptWorkOrder.Fields[YEAR_FLD].Text = dtmMonth.Year.ToString();
                        }
                        catch { }
                        try
                        {
                            rptWorkOrder.Fields[PRODUCTION_LINE_FLD].Text = txtProductionLine.Text;
                        }
                        catch { }
                        try
                        {
                            rptWorkOrder.Fields[WORK_ORDER_FLD].Text = txtWONo.Text;
                        }
                        catch { }
                        try
                        {
                            rptWorkOrder.Fields[MAS_LOC_FLD].Text = txtMasterLocation.Text;
                        }
                        catch { }
                        try
                        {
                            if (txtDescription.Text.Trim() != string.Empty)
                                rptWorkOrder.Fields[DESCRIPTION_FLD].Text = txtDescription.Text;
                            else
                            {
                                rptWorkOrder.Fields[DESCRIPTION_FLD].Visible = false;
                                rptWorkOrder.Fields[LABEL_PREFIX + PRO_WorkOrderMasterTable.DESCRIPTION_FLD].Visible = false;
                                rptWorkOrder.Fields[DIV_PREFIX + PRO_WorkOrderMasterTable.DESCRIPTION_FLD].Visible = false;
                            }
                        }
                        catch { }

                        #endregion

                        rptWorkOrder.Render();
                        // and show it in preview dialog				
                        C1PrintPreviewDialog printPreview = new C1PrintPreviewDialog();
                        printPreview.FormTitle = lblWorkOrderReport.Text;
                        printPreview.ReportViewer.NavigationPanelVisible = false;
                        printPreview.ReportViewer.PreviewPane.ZoomMode = ZoomModeEnum.PageWidth;
                        printPreview.ReportViewer.Document = rptWorkOrder.Document;
                        printPreview.Show();
                    }
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            finally
            {
                // restore cursor
                Cursor = Cursors.Default;
            }
        }
        /// <summary>
        /// Get working start time and end time of work center in a day
        /// </summary>
        /// <param name="pdtmCurrentDay">Current Day</param>
        /// <param name="pdtmStartTime">Start Time</param>
        /// <param name="pdtmEndTime">End Time</param>
        /// <param name="pdtmWorkingTime">Working Time</param>
        private void GetStartAndEndTime(DateTime pdtmCurrentDay, ref DateTime pdtmStartTime,
            ref DateTime pdtmEndTime, DataTable pdtmWorkingTime)
        {
            DataRow[] drowShifts = pdtmWorkingTime.Select(string.Empty, PRO_ShiftPatternTable.WORKTIMEFROM_FLD + " ASC");

            if (drowShifts.Length <= 0)
            {
                return;
            }
            //change shift configured day to working day
            pdtmStartTime = new DateTime(pdtmCurrentDay.Year, pdtmCurrentDay.Month, pdtmCurrentDay.Day,
                ((DateTime)drowShifts[0][PRO_ShiftPatternTable.WORKTIMEFROM_FLD]).Hour,
                ((DateTime)drowShifts[0][PRO_ShiftPatternTable.WORKTIMEFROM_FLD]).Minute,
                ((DateTime)drowShifts[0][PRO_ShiftPatternTable.WORKTIMEFROM_FLD]).Second);
            pdtmEndTime = new DateTime(pdtmCurrentDay.Year, pdtmCurrentDay.Month, pdtmCurrentDay.Day,
                ((DateTime)drowShifts[drowShifts.Length - 1][PRO_ShiftPatternTable.WORKTIMETO_FLD]).Hour,
                ((DateTime)drowShifts[drowShifts.Length - 1][PRO_ShiftPatternTable.WORKTIMETO_FLD]).Minute,
                ((DateTime)drowShifts[drowShifts.Length - 1][PRO_ShiftPatternTable.WORKTIMETO_FLD]).Second);
            double dblDiff = ((DateTime)drowShifts[drowShifts.Length - 1][PRO_ShiftPatternTable.WORKTIMETO_FLD]).
                Subtract((DateTime)drowShifts[0][PRO_ShiftPatternTable.WORKTIMEFROM_FLD]).Days;
            pdtmEndTime = pdtmEndTime.AddDays(dblDiff);
        }

        private void txtDCPCycle_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnDCPCycle_Click()";
            try
            {
                if (e.KeyCode == Keys.F4)
                    btnDCPCycle_Click(btnDCPCycle, null);
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void txtDCPCycle_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnDCPCycle_Click()";
            try
            {
                if (!txtDCPCycle.Modified)
                    return;
                if (txtDCPCycle.Text == string.Empty)
                {
                    // clear dcp cycle information
                    // cycle
                    txtDCPCycle.Text = string.Empty;
                    txtDCPCycle.Tag = null;
                    // description
                    txtDCPDescription.Text = string.Empty;
                    return;
                }
                DataRowView drwResult = null;
                Hashtable htbCondition = new Hashtable();

                if (cboCCN.SelectedValue != null)
                    htbCondition.Add(PRO_DCOptionMasterTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                else
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_RGA_CCN, MessageBoxIcon.Warning);
                    e.Cancel = true;
                    return;
                }
                drwResult = FormControlComponents.OpenSearchForm(PRO_DCOptionMasterTable.TABLE_NAME, PRO_DCOptionMasterTable.CYCLE_FLD, txtDCPCycle.Text.Trim(), htbCondition, false);
                if (drwResult != null)
                {
                    // cycle
                    txtDCPCycle.Text = drwResult[PRO_DCOptionMasterTable.CYCLE_FLD].ToString();
                    txtDCPCycle.Tag = drwResult[PRO_DCOptionMasterTable.DCOPTIONMASTERID_FLD];
                    // description
                    txtDCPDescription.Text = drwResult[PRO_DCOptionMasterTable.DESCRIPTION_FLD].ToString();
                }
                else
                    txtDCPCycle.Focus();
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void btnDCPCycle_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnDCPCycle_Click()";
            try
            {
                DataRowView drwResult = null;
                Hashtable htbCondition = new Hashtable();

                if (cboCCN.SelectedValue != null)
                    htbCondition.Add(PRO_DCOptionMasterTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                else
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_RGA_CCN, MessageBoxIcon.Warning);
                    cboCCN.Focus();
                    return;
                }
                drwResult = FormControlComponents.OpenSearchForm(PRO_DCOptionMasterTable.TABLE_NAME, PRO_DCOptionMasterTable.CYCLE_FLD, txtDCPCycle.Text.Trim(), htbCondition, true);
                if (drwResult != null)
                {
                    // cycle
                    txtDCPCycle.Text = drwResult[PRO_DCOptionMasterTable.CYCLE_FLD].ToString();
                    txtDCPCycle.Tag = drwResult[PRO_DCOptionMasterTable.DCOPTIONMASTERID_FLD];
                    // description
                    txtDCPDescription.Text = drwResult[PRO_DCOptionMasterTable.DESCRIPTION_FLD].ToString();
                }
                else
                    txtMasterLocation.Focus();
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }
        /// <summary>
        /// When user change production line, clear the grid
        /// </summary>
        /// <author>dungla</author>
        /// <date>17-04-2006</date>
        /// <purpose>fix bug 3771 for NganNT</purpose>
        private void ChangeProductionLine()
        {
            int intCount = dstGridData.Tables[0].Rows.Count;
            for (int i = intCount - 1; i >= 0; i--)
            {
                ArlWOLineID.Add(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString());
                dstGridData.Tables[0].Rows[i].Delete();
            }
            dgrdData.DataSource = dstGridData.Tables[0];
            FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayOut);
            ConfigGrid(false);
        }

        private void btnSaleOrderCode_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnSaleOrderCode_Click()";
            try
            {
                DataRowView drwResult = null;
                Hashtable htbCondition = new Hashtable();

                if (cboCCN.SelectedValue != null)
                {
                    htbCondition.Add(SO_SaleOrderMasterTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                    htbCondition.Add(SO_SaleOrderMasterTable.SHIPFROMLOCID_FLD, voMasLoc.MasterLocationID);
                    //					htbCondition.Add(ITM_ProductTable.PRODUCTID_FLD, dgrdData[dgrdData.Row, ITM_ProductTable.PRODUCTID_FLD].ToString());
                }
                drwResult = FormControlComponents.OpenSearchForm(SALE_ORDER_FOR_WOLINE_VIEWNAME, SALE_ORDER_CODE, txtSaleOrderCode.Text.ToString(), htbCondition, true);
                if (drwResult != null)
                {
                    FillSaleOrderData(drwResult.Row);
                }
                else
                {
                    txtFGoodsCode.Text = string.Empty;
                    lblFGoodsCode.Tag = 0;
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void btnFGoodsCode_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnFGoodsCode_Click()";
            try
            {
                if (FormControlComponents.CheckMandatory(txtMasterLocation))
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_RGA_MASTERLOCATION);
                    txtMasterLocation.Focus();
                    return;
                }
                if (txtSaleOrderCode.Text.Trim() != string.Empty)
                {
                    DataRowView drwResult = null;
                    Hashtable htbCondition = new Hashtable();
                    if (cboCCN.SelectedValue != null)
                    {
                        htbCondition = new Hashtable();
                        htbCondition.Add(SO_SaleOrderMasterTable.SALEORDERMASTERID_FLD, lblSaleOrderCode.Tag.ToString());
                        //						htbCondition.Add(SO_SaleOrderDetailTable.PRODUCTID_FLD, dgrdData[dgrdData.Row, ITM_ProductTable.PRODUCTID_FLD].ToString());
                    }
                    drwResult = FormControlComponents.OpenSearchForm(SO_SaleOrderDetailTable.TABLE_NAME, SO_SaleOrderDetailTable.FGOODSCODE_FLD, txtFGoodsCode.Text.ToString(), htbCondition, true);
                    if (drwResult != null)
                    {
                        FillSOLineData(drwResult.Row);
                    }
                }
                else
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_WO_SELECT_SALEORDER);
                    txtSaleOrderCode.Focus();
                    return;
                }

            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void txtSaleOrderCode_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtSaleOrderCode_Validating()";
            try
            {
                DataRowView drwResult = null;
                Hashtable htbCondition = new Hashtable();
                if (txtSaleOrderCode.Text.Trim() == string.Empty)
                {
                    btnSaleOrderCode.Focus();
                    txtFGoodsCode.Text = string.Empty;
                    lblFGoodsCode.Tag = 0;
                    return;
                }
                if (cboCCN.SelectedValue != null)
                {
                    htbCondition.Add(SO_SaleOrderMasterTable.CCNID_FLD, cboCCN.SelectedValue.ToString());
                    htbCondition.Add(SO_SaleOrderMasterTable.SHIPFROMLOCID_FLD, voMasLoc.MasterLocationID);
                    //					htbCondition.Add(ITM_ProductTable.PRODUCTID_FLD, dgrdData[dgrdData.Row, ITM_ProductTable.PRODUCTID_FLD].ToString());
                }
                drwResult = FormControlComponents.OpenSearchForm(SALE_ORDER_FOR_WOLINE_VIEWNAME, SALE_ORDER_CODE, txtSaleOrderCode.Text.ToString(), htbCondition, false);
                if (drwResult != null)
                {
                    FillSaleOrderData(drwResult.Row);
                }
                else
                {
                    txtFGoodsCode.Text = string.Empty;
                    lblFGoodsCode.Tag = 0;
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void txtFGoodsCode_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtFGoodsCode_Validating()";
            try
            {
                if (FormControlComponents.CheckMandatory(txtMasterLocation))
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_RGA_MASTERLOCATION);
                    txtMasterLocation.Focus();
                    return;
                }
                if (txtSaleOrderCode.Text.Trim() != string.Empty)
                {
                    DataRowView drwResult = null;
                    Hashtable htbCondition = new Hashtable();
                    if (cboCCN.SelectedValue != null)
                    {
                        htbCondition = new Hashtable();
                        htbCondition.Add(SO_SaleOrderMasterTable.SALEORDERMASTERID_FLD, lblSaleOrderCode.Tag.ToString());
                        //htbCondition.Add(SO_SaleOrderDetailTable.PRODUCTID_FLD, dgrdData[dgrdData.Row, ITM_ProductTable.PRODUCTID_FLD].ToString());
                    }
                    drwResult = FormControlComponents.OpenSearchForm(SO_SaleOrderDetailTable.TABLE_NAME, SO_SaleOrderDetailTable.FGOODSCODE_FLD, txtFGoodsCode.Text.ToString(), htbCondition, false);
                    if (drwResult != null)
                    {
                        FillSOLineData(drwResult.Row);
                    }
                }
                else
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_WO_SELECT_SALEORDER);
                    txtSaleOrderCode.Focus();
                    return;
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void txtFGoodsCode_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtFGoodsCode_KeyDown()";
            try
            {
                if ((e.KeyCode == Keys.F4) && (btnFGoodsCode.Enabled))
                {
                    btnFGoodsCode_Click(sender, e);
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void txtSaleOrderCode_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtSaleOrderCode_KeyDown()";
            try
            {
                if ((e.KeyCode == Keys.F4) && (btnSaleOrderCode.Enabled))
                {
                    btnSaleOrderCode_Click(sender, e);
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }
        private void ShowWorkOrderLineReport(object sender, System.EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                //return if no record was selected
                if (dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD] == DBNull.Value)
                {
                    PCSMessageBox.Show(ErrorCode.MSG_LABORTIME_SELECTWODETAIL, MessageBoxIcon.Warning);
                    return;
                }
                ReportDefinitionFolder = Application.StartupPath + @"\ReportDefinition";
                if (!File.Exists(ReportDefinitionFolder + @"\" + ReportWorkOrderLine))
                {
                    PCSMessageBox.Show(ErrorCode.MESSAGE_REPORT_TEMPLATE_FILE_NOT_FOUND, MessageBoxIcon.Error);
                    return;
                }

                #region Rendering Report

                C1Report rptWorkOrder = new C1Report();
                try
                {
                    string[] arrstrReportInDefinitionFile = rptWorkOrder.GetReportInfo(
                        ReportDefinitionFolder + "\\" + ReportWorkOrderLine);
                    rptWorkOrder.Load(ReportDefinitionFolder + "\\" + ReportWorkOrderLine, arrstrReportInDefinitionFile[0]);
                    arrstrReportInDefinitionFile = null;
                }
                catch
                {
                    return;
                }
                rptWorkOrder.Layout.PaperSize = PaperKind.A4;

                #endregion

                #region Modify the report layout

                const string STT_FLD = "fldSTT";
                const string FGOODSCODE_FLD = "fldFGoodsCode";
                const string PARTNAME_FLD = "fldPartName";
                const string PARTNO_FLD = "fldPartNo";
                const string QUANTITY_FLD = "fldQuantity";
                const string STARTDATE_FLD = "fldStartDate";
                const string ENDDATE_FLD = "fldEndDate";
                const string COMMENT_FLD = "fldComment";
                const string ORDERQUANTITY = "OrderQuantity";
                const string SERVERDATE = "fldServerDate";

                try
                {
                    rptWorkOrder.Fields[STT_FLD].Text = dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.LINE_FLD].ToString();
                }
                catch { }
                try
                {
                    rptWorkOrder.Fields[FGOODSCODE_FLD].Text = txtFGoodsCode.Text;
                }
                catch { }
                try
                {
                    rptWorkOrder.Fields[PARTNAME_FLD].Text = dgrdData[dgrdData.Row, ITM_ProductTable.TABLE_NAME + ITM_ProductTable.DESCRIPTION_FLD].ToString();
                }
                catch { }
                try
                {
                    rptWorkOrder.Fields[PARTNO_FLD].Text = dgrdData[dgrdData.Row, ITM_ProductTable.CODE_FLD].ToString();
                }
                catch { }
                try
                {
                    rptWorkOrder.Fields[QUANTITY_FLD].Text = dgrdData[dgrdData.Row, ORDERQUANTITY].ToString();
                }
                catch { }
                try
                {
                    rptWorkOrder.Fields[STARTDATE_FLD].Text = Convert.ToDateTime(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STARTDATE_FLD]).ToString(Constants.DATETIME_FORMAT_HOUR);
                }
                catch { }
                try
                {
                    rptWorkOrder.Fields[ENDDATE_FLD].Text = Convert.ToDateTime(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.DUEDATE_FLD]).ToString(Constants.DATETIME_FORMAT_HOUR);
                }
                catch { }
                try
                {
                    rptWorkOrder.Fields[COMMENT_FLD].Text = txtDescription.Text;
                }
                catch { }

                try
                {
                    DateTime dtmServerDate = new UtilsBO().GetDBDate();
                    rptWorkOrder.Fields[SERVERDATE].Text = "Ngày " + dtmServerDate.Day + " tháng " + dtmServerDate.Month.ToString("00") + " năm " + dtmServerDate.Year;
                }
                catch { }

                #endregion

                rptWorkOrder.Render();
                // and show it in preview dialog				
                C1PrintPreviewDialog printPreview = new C1PrintPreviewDialog();
                printPreview.ReportViewer.NavigationPanelVisible = false;
                printPreview.ReportViewer.PreviewPane.ZoomMode = ZoomModeEnum.PageWidth;
                printPreview.ReportViewer.Document = rptWorkOrder.Document;
                printPreview.Show();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }

        private void btnPrintWOLine_Click(object sender, System.EventArgs e)
        {
            ShowWorkOrderLineReport(this, null);
        }

        private void btnEditBOM_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnBOM_Click()";
            try
            {
                if (dgrdData.Row < dgrdData.RowCount)
                {
                    string strFGoodsCode = dgrdData[dgrdData.Row, SO_SaleOrderDetailTable.FGOODSCODE_FLD].ToString();
                    int intWODetailID = Convert.ToInt32(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD]);
                    int intProductID = Convert.ToInt32(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.PRODUCTID_FLD]);
                    // use unrelease status in order to change bom
                    WOBOM frmWOBOM = new WOBOM(strFGoodsCode, intWODetailID, (int)WOLineStatus.Unreleased, voWorkOrderMaster.WorkOrderMasterID, voWorkOrderMaster.WorkOrderNo, intProductID);
                    frmWOBOM.ChangeBom = true;
                    frmWOBOM.ShowDialog();
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }

        private void btnSuaBSX_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnSuaBSX_Click()";
            try
            {
                if (dgrdData.Row < dgrdData.RowCount)
                {
                    int intProductionLineID = 0;
                    try
                    {
                        intProductionLineID = int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.PRODUCTIONLINEID_FLD].ToString());
                    }
                    catch { }
                    WORouting frmWORouting = new WORouting(int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD].ToString())
                        , int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.PRODUCTID_FLD].ToString())
                        , int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.STATUS_FLD].ToString())
                        , int.Parse(dgrdData[dgrdData.Row, PRO_WorkOrderDetailTable.WORKORDERMASTERID_FLD].ToString())
                        , intProductionLineID);
                    frmWORouting.Edit = true;
                    frmWORouting.ShowDialog();
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                }
            }
        }
    }


    public enum WOFormState
    {
        Normal = 1,
        CPONewWO = 2,
        CPOExistWO = 3
    }
}
